Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. type FirstServiceConfig struct {
  8. FirstServiceKey string
  9. FirstServiceProject string
  10. }
  11.  
  12. type SecondServiceConfig struct {
  13. SecondServiceUsername string
  14. SecondServicePassword string
  15. }
  16.  
  17. type Config struct {
  18. Address string
  19. *FirstServiceConfig
  20. *SecondServiceConfig
  21. }
  22.  
  23. var (
  24. defaultFirstServiceConfig = FirstServiceConfig{
  25. FirstServiceKey: "public_key",
  26. FirstServiceProject: "little_test",
  27. }
  28. defaultSecondServiceConfig = SecondServiceConfig{
  29. SecondServiceUsername: "guillaume",
  30. SecondServicePassword: "qwerty",
  31. }
  32. )
  33.  
  34. func NewConfig(address string) Config {
  35.  
  36. c := Config {
  37. Address: address,
  38. }
  39. c.FirstServiceConfig = &defaultFirstServiceConfig
  40. c.SecondServiceConfig = &defaultSecondServiceConfig
  41. return c
  42. }
  43.  
  44. func main() {
  45.  
  46. config := NewConfig("127.0.0.1")
  47. fmt.Printf("%v\n",config)
  48. fmt.Printf("%v\n",config.FirstServiceConfig)
  49. fmt.Printf("%v\n",config.SecondServiceConfig)
  50. // Direct access to embed struct fields
  51. fmt.Printf("Second service username is %s\n",config.SecondServicePassword)
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement