title: Go Setup sidebar_position: 4 id: go license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Fory Go provides xlang and native Object Serialization, generated models, and Fory gRPC. It is published as github.com/apache/fory/go/fory and requires Go 1.25 or later.
go version
go env GOPROXY
Create a module and install the released Fory module:
mkdir fory-example cd fory-example go mod init example.com/fory-example go get github.com/apache/fory/go/fory@v1.6.1
If a Go proxy has not picked up a new submodule tag yet, retry later or use GOPROXY=direct temporarily.
package main import ( "fmt" "github.com/apache/fory/go/fory" ) type User struct { ID int64 Name string } func main() { f := fory.New(fory.WithXlang(true)) if err := f.RegisterStruct(User{}, 1); err != nil { panic(err) } bytes, err := f.Serialize(&User{ID: 1, Name: "Alice"}) if err != nil { panic(err) } var decoded User if err := f.Deserialize(bytes, &decoded); err != nil { panic(err) } fmt.Println(decoded.Name) }
go run .
Use xlang mode for cross-language data and native mode for Go-only data. Continue with Go Object Serialization, configuration, and schema evolution.