-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
894 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Package {{ .PackageName }} provides a client for the "{{ .CanisterName }}" canister. | ||
// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. | ||
package {{ .PackageName }} | ||
|
||
import ( | ||
"github.com/aviate-labs/agent-go" | ||
{{ if .UsedIDL }}"github.com/aviate-labs/agent-go/candid/idl"{{ end }} | ||
"github.com/aviate-labs/agent-go/principal" | ||
) | ||
|
||
{{- range .Definitions }} | ||
|
||
type {{ .Name }} {{ if .Eq }}= {{end}}{{ .Type }} | ||
{{- end }} | ||
|
||
// {{ .AgentName }}Agent is a client for the "{{ .CanisterName }}" canister. | ||
type {{ .AgentName }}Agent struct { | ||
a *agent.Agent | ||
canisterId principal.Principal | ||
} | ||
|
||
// New{{ .AgentName }}Agent creates a new agent for the "{{ .CanisterName }}" canister. | ||
func New{{ .AgentName }}Agent(canisterId principal.Principal, config agent.Config) (*{{ .AgentName }}Agent, error) { | ||
a, err := agent.New(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &{{ .AgentName }}Agent{ | ||
a: a, | ||
canisterId: canisterId, | ||
}, nil | ||
} | ||
{{- range .Methods }} | ||
|
||
// {{ .Name }} calls the "{{ .RawName }}" method on the "{{ $.CanisterName }}" canister. | ||
func (a {{ $.AgentName }}Agent) {{ .Name }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} {{ $e.Type }}{{ end }}) {{ if .ReturnTypes }}({{ range .ReturnTypes }}*{{ . }}, {{ end }}error){{ else }}error{{ end }} { | ||
{{ range $i, $e := .ReturnTypes -}} | ||
var r{{ $i }} {{ $e }} | ||
{{ end -}} | ||
if err := a.a.{{ .Type }}( | ||
a.canisterId, | ||
"{{ .RawName }}", | ||
[]any{{ "{" }}{{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }}{{ end }}{{ "}" }}, | ||
[]any{{ "{" }}{{ range $i, $e := .ReturnTypes }}{{ if $i }}, {{ end }}&r{{ $i }}{{ end }}{{ "}"}}, | ||
); err != nil { | ||
return {{ range .ReturnTypes }}nil, {{ end }}err | ||
} | ||
return {{ range $i, $_ := .ReturnTypes }}&r{{ $i }}, {{ end }}nil | ||
} | ||
|
||
// {{ .Name }}{{ .Type }} creates an indirect representation of the "{{ .RawName }}" method on the "{{ $.CanisterName }}" canister. | ||
func (a {{ $.AgentName }}Agent) {{ .Name }}{{ .Type }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} {{ $e.Type }}{{ end }}) (*agent.{{ .Type }},error) { | ||
return a.a.Create{{ .Type }}( | ||
a.canisterId, | ||
"{{ .RawName }}",{{ range $i, $e := .ArgumentTypes }} | ||
{{ $e.Name }},{{ end }} | ||
) | ||
} | ||
|
||
{{- end }} |
Oops, something went wrong.