bug: fail to copy field named with struct
morya opened this issue · 0 comments
morya commented
go-model
won't copy filed with the same type name,
following are the reproduce code.
package main
import (
"encoding/json"
"log"
"golang.org/x/oauth2"
go_model "gopkg.in/jeevatkm/go-model.v1"
)
type Endpoint struct {
AuthURL string `yaml:"auth_url" validate:"required,min=1"`
TokenURL string `yaml:"token_url" validate:"required,min=1"`
AuthStyle oauth2.AuthStyle `yaml:"auth_style" validate:"required,oneof=0 1 2"`
}
type OauthConfig struct {
ClientID string `yaml:"client_id" validate:"required,min=1"`
ClientSecret string `yaml:"client_secret" validate:"required,min=1"`
Endpoint Endpoint
RedirectURL string `yaml:"redirect_url" validate:"required,min=1"`
Scopes []string `yaml:"scopes" example:"state"`
}
func DumpJson(obj interface{}) string {
data, _ := json.Marshal(obj)
return string(data)
}
func main() {
var sample = OauthConfig{
ClientID: "aa",
ClientSecret: "bb",
Endpoint: Endpoint{
AuthURL: "https://sample.com",
TokenURL: "https://sample.com",
AuthStyle: 1,
},
RedirectURL: "https://sample.com",
Scopes: []string{"state"},
}
var d = oauth2.Config{}
go_model.Copy(&d, sample)
log.Println(DumpJson(d))
}
sample code output:
2022/03/24 11:16:32 {"ClientID":"aa","ClientSecret":"bb","Endpoint":{"AuthURL":"","TokenURL":"","AuthStyle":0},"RedirectURL":"https://sample.com","Scopes":["state"]}
Endpoint fields are empty.