Skip to content

Instantly share code, notes, and snippets.

@curlyz
Created March 24, 2022 02:27
Show Gist options
  • Save curlyz/4c185c1d0bab1245957e069c812f7309 to your computer and use it in GitHub Desktop.
Save curlyz/4c185c1d0bab1245957e069c812f7309 to your computer and use it in GitHub Desktop.
go_generic_struct
  type OrderRevenue interface {
          MarshalMyself() ([]byte, error)
  }

  type Anonymous struct {}
  func (a Anonymous) MarshalMyself() ([]byte, error) {
          // implementation's up to you
          return []byte{}, nil
  }

  // the function signature
  generateResponse(rows *sqlx.Rows, structSlice []OrderRevenue, structBody Body) ([]Body, error) {
          // ...
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment