-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Better strategy to parse metadata #92
Comments
Maybe a better use case example: package main
import (
"encoding/json"
"fmt"
)
type Meta struct {
Theme *string `json:"theme"`
}
var meta1 Meta
var meta2 Meta
var meta3 Meta
var meta4 Meta
func printTheme(m *Meta, j string) {
json.Unmarshal([]byte(j), m)
if m.Theme == nil {
fmt.Printf("Theme not set for %s\n", j)
} else {
fmt.Printf("Theme is %s for %s\n", *m.Theme, j)
}
}
func main() {
printTheme(&meta1, "{}")
printTheme(&meta2, `{"theme": "dark"}`)
printTheme(&meta3, `{"theme": ""}`)
printTheme(&meta4, `{"notATheme": "dark"}`)
} Output:
|
This is a great idea! |
@cuducos do you want me to implement this or would you like to while adding the author/date metadata. Looks like you have a good handle on this though! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
We have this TODO:
slides/internal/meta/meta.go
Line 38 in 1968b71
Describe the solution you'd like
And I think that using
*string
instead ofstring
would help us differentiate something not set in theheader
from things set to an empty string.I added new, better examples below, so collapsed this block ; )
This outputs:
The text was updated successfully, but these errors were encountered: