PHP serialize() and unserialize() for Go.
go get -u github.com/elliotchance/phpserialize
phpserialize
requires Go 1.8+.
package main
import (
"fmt"
"github.com/elliotchance/phpserialize"
)
func main() {
out, err := phpserialize.Marshal(3.2, nil)
if err != nil {
panic(err)
}
fmt.Println(string(out))
var in float64
err = phpserialize.Unmarshal(out, &in)
fmt.Println(in)
}
package main
import (
"fmt"
"github.com/elliotchance/phpserialize"
)
type MyStruct struct {
// Will be marhsalled as my_purpose
MyPurpose string `php:"my_purpose"`
// Will be marshalled as my_motto, and only if not a nil pointer
MyMotto *string `php:"my_motto,omitnilptr"`
// Will not be marshalled
MySecret string `php:"-"`
}
func main() {
my := MyStruct{
MyPurpose: "No purpose",
MySecret: "Has a purpose",
}
out, err := phpserialize.Marshal(my, nil)
if err != nil {
panic(err)
}
fmt.Println(out)
}