Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct { AgentName string ModulePath string CanisterName string CanisterID *principal.Principal PackageName string ServiceDescription did.Description // contains filtered or unexported fields }
Generator is a generator for a given service description.
func NewGenerator ¶
NewGenerator creates a new generator for the given service description.
Example ¶
package main import ( "fmt" "github.com/aviate-labs/agent-go/gen" ) func main() { g, err := gen.NewGenerator("test", "test", "test", []rune("service : { inc: () -> (nat) }")) if err != nil { panic(err) } raw, err := g.Generate() if err != nil { panic(err) } fmt.Println(string(raw)) }
Output: // Package test provides a client for the "test" canister. // Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package test import ( "github.com/aviate-labs/agent-go" "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/principal" ) // TestAgent is a client for the "test" canister. type TestAgent struct { *agent.Agent CanisterId principal.Principal } // NewTestAgent creates a new agent for the "test" canister. func NewTestAgent(canisterId principal.Principal, config agent.Config) (*TestAgent, error) { a, err := agent.New(config) if err != nil { return nil, err } return &TestAgent{ Agent: a, CanisterId: canisterId, }, nil } // Inc calls the "inc" method on the "test" canister. func (a TestAgent) Inc() (*idl.Nat, error) { var r0 idl.Nat if err := a.Agent.Call( a.CanisterId, "inc", []any{}, []any{&r0}, ); err != nil { return nil, err } return &r0, nil }
Example (Indirect) ¶
package main import ( "fmt" "github.com/aviate-labs/agent-go/gen" ) func main() { g, err := gen.NewGenerator("test", "test", "test", []rune("service : { inc: () -> (nat) }")) if err != nil { panic(err) } raw, err := g.Indirect().Generate() if err != nil { panic(err) } fmt.Println(string(raw)) }
Output: // Package test provides a client for the "test" canister. // Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package test import ( "github.com/aviate-labs/agent-go" "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/principal" ) // TestAgent is a client for the "test" canister. type TestAgent struct { *agent.Agent CanisterId principal.Principal } // NewTestAgent creates a new agent for the "test" canister. func NewTestAgent(canisterId principal.Principal, config agent.Config) (*TestAgent, error) { a, err := agent.New(config) if err != nil { return nil, err } return &TestAgent{ Agent: a, CanisterId: canisterId, }, nil } // Inc calls the "inc" method on the "test" canister. func (a TestAgent) Inc() (*idl.Nat, error) { var r0 idl.Nat if err := a.Agent.Call( a.CanisterId, "inc", []any{}, []any{&r0}, ); err != nil { return nil, err } return &r0, nil } // IncCall creates an indirect representation of the "inc" method on the "test" canister. func (a TestAgent) IncCall() (*agent.CandidAPIRequest, error) { return a.Agent.CreateCandidAPIRequest( agent.RequestTypeCall, a.CanisterId, "inc", ) }
Click to show internal directories.
Click to hide internal directories.