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

Allow non-exported fields with reform tag #169

Open
AlekSi opened this issue Aug 14, 2018 · 2 comments
Open

Allow non-exported fields with reform tag #169

AlekSi opened this issue Aug 14, 2018 · 2 comments
Labels

Comments

@AlekSi
Copy link
Member

AlekSi commented Aug 14, 2018

Consider the following code:

package audit

type Message struct {
	ID      string `reform:"id,pk"`
	Method  string `reform:"method"`
	Payload interface{}
	body    []byte `reform:"body"`
}

func (m *Message) BeforeInsert() error {
	b, err := json.Marshal(m.Payload)
	m.body = b
	return err
}

An external user of that package can set Payload, but it is always stored in serialized form.

Currently, it is not possible due to check in reform tool: Message has non-exported field body with "reform:" tag, it is not allowed. But we don't have a reason for that check anymore – generated code can access this field directly, no reflection (which almost always works only for exported fields) is required.

@AlekSi AlekSi added the triage label Aug 14, 2018
@AlekSi
Copy link
Member Author

AlekSi commented Aug 14, 2018

@rumyantseva Does it make sense to you?

@rumyantseva
Copy link
Collaborator

@AlekSi I'm afraid, I'm not 100% understand the problem. What is the goal? Is the idea that an external user can set a field in a very "generic" form (interface{}) but wants to serialize it in a specific manner before insert? Could you give me an example? Smth about JSONB fields in Postgres?

I'd say this implementation look like "костыль" a little bit but on the other hand it gives some flexibility. Let me think about it a little bit.

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

No branches or pull requests

2 participants