go - Multiple structs with different composition -


i have problem not sure how solve in go. need make client talks json based api.

so thought use composition build struct similar below.

type (     basedata struct {         commonfields string     }      data struct {         basedata         result string     } ) 

now send data struct api , unmarshal response results, far.

now issue have different requests send require different "results" composition , therefore need have many definitions of data struct in same package, no good.

i struggling see how should done. pointers in direction great.

do not create model structure mirrors or imitates api want use. design model in way makes sense program, following ddd principles @ high conceptual level, , solid principles @ implementation level, example.

most probably:

  • you don't need features of foreign api. adhering structures, implement lot of boilerplate serves no purpose of own in program.
  • you don't want program break down due minor changes in foreign api.

create layer in program communicating foreign api, , make rest of program depend on layer, never directly on foreign api. way, if changes in api, need change communication layer, rest of program can continue working unaffected.

in communication layer, use whatever structures needed talk api. not use structures not needed. , convert these structures structures used within rest of program. may involve lot of manual copying might not seem pretty @ first, it's way protect program external changes.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -