mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-02 20:02:53 +00:00
331ec59dec
This commit gets rid of contain-it-all structs and instead opt for interface union types containing underlying concrete types with no overloading. The code is much more verbose by doing this, but the API is much nicer to use. The only disadvantage in that regard is the interface assertion being too verbose and risky for users at times.
39 lines
1.5 KiB
Cheetah
39 lines
1.5 KiB
Cheetah
// Code generated by gensnowflake. DO NOT EDIT.
|
|
|
|
package {{ .Package }}
|
|
|
|
{{ $dot := "" }}
|
|
|
|
{{ if .ImportDiscord }}
|
|
{{ $dot = "discord." }}
|
|
import "github.com/diamondburned/arikawa/v3/discord"
|
|
{{ end }}
|
|
|
|
import "time"
|
|
|
|
{{ range .Snowflakes }}
|
|
|
|
// {{ .TypeName }} is the snowflake type for a {{ .TypeName }}.
|
|
type {{.TypeName}} {{$dot}}Snowflake
|
|
|
|
// Null{{.TypeName}} gets encoded into a null. This is used for optional and nullable snowflake fields.
|
|
const Null{{.TypeName}} = {{.TypeName}}({{$dot}}NullSnowflake)
|
|
|
|
func (s {{.TypeName}}) MarshalJSON() ([]byte, error) { return {{$dot}}Snowflake(s).MarshalJSON() }
|
|
func (s *{{.TypeName}}) UnmarshalJSON(v []byte) error { return (*{{$dot}}Snowflake)(s).UnmarshalJSON(v) }
|
|
|
|
// String returns the ID, or nothing if the snowflake isn't valid.
|
|
func (s {{.TypeName}}) String() string { return {{$dot}}Snowflake(s).String() }
|
|
|
|
// IsValid returns whether or not the snowflake is valid.
|
|
func (s {{.TypeName}}) IsValid() bool { return {{$dot}}Snowflake(s).IsValid() }
|
|
|
|
// IsNull returns whether or not the snowflake is null.
|
|
func (s {{.TypeName}}) IsNull() bool { return {{$dot}}Snowflake(s).IsNull() }
|
|
|
|
func (s {{.TypeName}}) Time() time.Time { return {{$dot}}Snowflake(s).Time() }
|
|
func (s {{.TypeName}}) Worker() uint8 { return {{$dot}}Snowflake(s).Worker() }
|
|
func (s {{.TypeName}}) PID() uint8 { return {{$dot}}Snowflake(s).PID() }
|
|
func (s {{.TypeName}}) Increment() uint16 { return {{$dot}}Snowflake(s).Increment() }
|
|
{{ end }}
|