This repo was deprecated. I was young, inexperienced, and I was thinking about the wrong thing. I'm sorry. :)
Various helpful golang structs package
Default value is zero value.
- date
- time
Default value is null value.
- string
- bool
- int64
- float64
- time
- date
Get package via go get github.com/smgladkovskiy/structs
or via dep ensure add github.com/smgladkovskiy/structs
if you use dep.
Import package in your go file:
package main
import (
"github.com/smgladkovskiy/structs" // if need to set date or time format
"github.com/smgladkovskiy/structs/null" // if nullables are used
"github.com/smgladkovskiy/structs/zero" // if zeroables are used
)
Use in code:
package main
import (
"fmt"
"time"
"github.com/smgladkovskiy/structs" // if need to set date or time format
"github.com/smgladkovskiy/structs/null" // if nullables are used
"github.com/smgladkovskiy/structs/zero" // if zeroables are used
)
func main() {
structs.TimeFormat = func() string {
return time.RFC1123
}
customTime, _ := null.NewTime(time.Now())
if !customTime.Valid {
fmt.Println("time is null")
return
}
fmt.Printf("custom time is %s", customTime.Time)
}
Initiates new zero value of XXX type, using Scan
method with passed value.
Initiates new nullable value of XXX type, using Scan
method with passed value.
Initiates new null.String
type value for passed format string and format variables. Available for strings.
There is an opportunity for zero.Time
and null.Time
types to set time format witch will be used with (Un)MarshallJSON methods.
To override default package format for time (time.RFC3339
), there must be an stucts.TimeFormat
function
overriding in your app at the configuration or init level:
package main
import (
"time"
"github.com/smgladkovskiy/structs"
)
func main() {
structs.TimeFormat = func() string {
return time.RFC1123
}
}
For zero.Date
and null.Date
types there is the same thing with format for (Un)MarshallJSON.
Default package date format (YYYY-MM-DD
) must be overridden with stucts.DateFormat
function:
package main
import (
"github.com/smgladkovskiy/structs"
)
func init() {
structs.DateFormat = func() string {
return "02.01.2006"
}
}