-
Notifications
You must be signed in to change notification settings - Fork 6
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
A slice of structs #1
Comments
The Source package main
import (
"fmt"
"github.com/goji/param"
"github.com/kr/pretty"
"net/url"
"time"
)
type Configs struct {
AppId string
Key string
Port string `param:"port"`
Groups map[string]Group `param:"groups"`
}
type Group struct {
Id string `param:"id"`
Rm string `param:"rm"`
Bans Ban `param:"bans"`
}
type Ban struct {
Enable bool `param:"enable"`
Reason string `param:"reason"`
Comment string `param:"comment"`
Duration time.Duration `param:"duration"`
Visible bool `param:"visible"`
}
func main() {
scfg := Configs{}
err := param.Parse(url.Values{
"port": {"8998"},
"groups[0][id]": {"123"},
"groups[0][rm]": {"all"},
"groups[0][bans][enable]": {"true"},
"groups[0][bans][reason]": {"5"},
"groups[0][bans][comment]": {"flooderast"},
"groups[0][bans][duration]": {"168"},
"groups[0][bans][visible]": {"false"},
"groups[1][id]": {"123"},
"groups[1][rm]": {"all"},
"groups[1][bans][enable]": {"true"},
"groups[1][bans][reason]": {"5"},
"groups[1][bans][comment]": {"no flood"},
"groups[1][bans][duration]": {"168"},
"groups[1][bans][visible]": {"false"},
}, &scfg)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%# v", pretty.Formatter(scfg))
}
} Result/output
|
So slices can only contain non-nested types due to a limitation in the implementation (I don't think it would be too hard to add if you felt inclined). The other thing looks like a bug. This week is super busy for me but I'll investigate / fix it as soon as I get a chance. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
Is it possible to use a slice of structs, like here?
How?
The text was updated successfully, but these errors were encountered: