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.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.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.CreateCandidAPIRequest( agent.RequestTypeCall, a.CanisterId, "inc", ) }
Example (Tags) ¶
package main
import (
"fmt"
"github.com/aviate-labs/agent-go/gen"
)
func main() {
g, err := gen.NewGenerator("test", "test", "test", []rune("type resp = record { nat; variant { ok; err } }; service : { test: () -> (vec resp) }"))
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" ) type Resp struct { Field0 idl.Nat `ic:"0,tuple" json:"0"` Field1 struct { Ok *idl.Null `ic:"ok,variant" json:"ok,omitempty"` Err *idl.Null `ic:"err,variant" json:"err,omitempty"` } `ic:"1,tuple" json:"1"` } // 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 } // Test calls the "test" method on the "test" canister. func (a TestAgent) Test() (*[]Resp, error) { var r0 []Resp if err := a.Call( a.CanisterId, "test", []any{}, []any{&r0}, ); err != nil { return nil, err } return &r0, nil }
Click to show internal directories.
Click to hide internal directories.