This repository has been archived by the owner on May 17, 2024. It is now read-only.
generated from findy-network/findy-template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_agent.go
82 lines (71 loc) · 2.2 KB
/
api_agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Aries Agent Test Harness Backchannel API
*
* This page documents the backchannel API the test harness uses to communicate with agents under tests. For more information checkout the [Aries Interoperability Information](http://aries-interop.info) page.
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
import (
"encoding/json"
"net/http"
"strings"
)
// AgentApiController binds http requests to an api service and writes the service results to the http response
type AgentApiController struct {
service AgentApiServicer
errorHandler ErrorHandler
}
// AgentApiOption for how the controller is set up.
type AgentApiOption func(*AgentApiController)
// WithAgentApiErrorHandler inject ErrorHandler into controller
func WithAgentApiErrorHandler(h ErrorHandler) AgentApiOption {
return func(c *AgentApiController) {
c.errorHandler = h
}
}
// NewAgentApiController creates a default api controller
func NewAgentApiController(s AgentApiServicer, opts ...AgentApiOption) Router {
controller := &AgentApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the AgentApiController
func (c *AgentApiController) Routes() Routes {
return Routes{
{
"AgentStart",
strings.ToUpper("Post"),
"/agent/command/agent/start",
c.AgentStart,
},
}
}
// AgentStart - (re)start the agent
func (c *AgentApiController) AgentStart(w http.ResponseWriter, r *http.Request) {
agentStartRequestParam := AgentStartRequest{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&agentStartRequestParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertAgentStartRequestRequired(agentStartRequestParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.AgentStart(r.Context(), agentStartRequestParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}