项目作者: ashkan90

项目描述 :
accessing structs with string via dot notation.
高级语言: Go
项目地址: git://github.com/ashkan90/dot_notation.git
创建时间: 2020-03-17T12:56:22Z
项目社区:https://github.com/ashkan90/dot_notation

开源协议:

下载


Golang -Struct Based String-Dot-Notation Accessor

Accessing structs with string never been get this much easy!! :D

Usage

!Note(You need to be careful when you’re creating your struct. The fields have to be exported.)
  1. type g struct {
  2. Customer struct {
  3. Details struct {
  4. Profile struct {
  5. Name string
  6. }
  7. }
  8. }
  9. }
  10. func main() {
  11. ng := &g{
  12. Customer: struct{
  13. Details struct{
  14. Profile struct{
  15. Name string
  16. }
  17. }
  18. }{
  19. Details: struct{
  20. Profile struct{
  21. Name string
  22. }
  23. }{
  24. Profile: struct{
  25. Name string
  26. }{ Name: "Emirhan" }}},
  27. }
  28. fmt.Println(Notate(ng, "Customer.Details.Profile.Name"))
  29. }