Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fail to copy field named with struct #15

Open
morya opened this issue Mar 24, 2022 · 0 comments
Open

bug: fail to copy field named with struct #15

morya opened this issue Mar 24, 2022 · 0 comments

Comments

@morya
Copy link

morya commented Mar 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant