example_test.go 728 B

12345678910111213141516171819202122232425262728293031
  1. package dsn_test
  2. import (
  3. "log"
  4. "go-common/library/conf/dsn"
  5. xtime "go-common/library/time"
  6. )
  7. // Config struct
  8. type Config struct {
  9. Network string `dsn:"network" validate:"required"`
  10. Host string `dsn:"host" validate:"required"`
  11. Username string `dsn:"username" validate:"required"`
  12. Password string `dsn:"password" validate:"required"`
  13. Timeout xtime.Duration `dsn:"query.timeout,1s"`
  14. Offset int `dsn:"query.offset" validate:"gte=0"`
  15. }
  16. func ExampleParse() {
  17. cfg := &Config{}
  18. d, err := dsn.Parse("tcp://root:toor@172.12.12.23:2233?timeout=10s")
  19. if err != nil {
  20. log.Fatal(err)
  21. }
  22. _, err = d.Bind(cfg)
  23. if err != nil {
  24. log.Fatal(err)
  25. }
  26. log.Printf("%v", cfg)
  27. }