~sircmpwn/public-inbox

go-bare: Ignore fields with a tag of "-" v1 PROPOSED

Adnan Maolood: 1
 Ignore fields with a tag of "-"

 2 files changed, 12 insertions(+), 0 deletions(-)
#344092 .build.yml success
Yep
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/15092/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH go-bare] Ignore fields with a tag of "-" Export this patch

---
 marshal.go   | 6 ++++++
 unmarshal.go | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/marshal.go b/marshal.go
index 55acce7..a5b6171 100644
--- a/marshal.go
+++ b/marshal.go
@@ -127,11 +127,17 @@ func encodeStruct(t reflect.Type) encodeFunc {
	encoders := make([]encodeFunc, n)
	for i := 0; i < n; i++ {
		field := t.Field(i)
		if field.Tag.Get("bare") == "-" {
			continue
		}
		encoders[i] = getEncoder(field.Type)
	}

	return func(w *Writer, v reflect.Value) error {
		for i := 0; i < n; i++ {
			if encoders[i] == nil {
				continue
			}
			err := encoders[i](w, v.Field(i))
			if err != nil {
				return err
diff --git a/unmarshal.go b/unmarshal.go
index 85fe5ef..7ba4b56 100644
--- a/unmarshal.go
+++ b/unmarshal.go
@@ -125,11 +125,17 @@ func decodeStruct(t reflect.Type) decodeFunc {
	decoders := make([]decodeFunc, n)
	for i := 0; i < n; i++ {
		field := t.Field(i)
		if field.Tag.Get("bare") == "-" {
			continue
		}
		decoders[i] = getDecoder(field.Type)
	}

	return func(r *Reader, v reflect.Value) error {
		for i := 0; i < n; i++ {
			if decoders[i] == nil {
				continue
			}
			err := decoders[i](r, v.Field(i))
			if err != nil {
				return err
-- 
2.29.2
builds.sr.ht
go-bare/patches/.build.yml: SUCCESS in 29s

[Ignore fields with a tag of "-"][0] from [Adnan Maolood][1]

[0]: https://lists.sr.ht/~sircmpwn/public-inbox/patches/15092
[1]: mailto:me@adnano.co

✓ #344092 SUCCESS go-bare/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/344092
Should I add tests and some documentation?