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
/
main.go
138 lines (108 loc) · 4.67 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* 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 main
import (
"bytes"
"io"
"log"
"net/http"
"os"
"strings"
"time"
"github.com/findy-network/findy-agent-backchannel/agent"
openapi "github.com/findy-network/findy-agent-backchannel/openapi"
"github.com/gorilla/mux"
"github.com/lainio/err2/try"
)
func createRouter(a *agent.Agent) *mux.Router {
AgentApiService := openapi.NewAgentApiService()
AgentApiController := openapi.NewAgentApiController(AgentApiService)
ConnectionApiService := openapi.NewConnectionApiService(a)
ConnectionApiController := openapi.NewConnectionApiController(ConnectionApiService)
CoordinateMediationApiService := openapi.NewCoordinateMediationApiService()
CoordinateMediationApiController := openapi.NewCoordinateMediationApiController(CoordinateMediationApiService)
CredentialApiService := openapi.NewCredentialApiService(a)
CredentialApiController := openapi.NewCredentialApiController(CredentialApiService)
CredentialDefinitionApiService := openapi.NewCredentialDefinitionApiService(a)
CredentialDefinitionApiController := openapi.NewCredentialDefinitionApiController(CredentialDefinitionApiService)
DIDApiService := openapi.NewDIDApiService(a)
DIDApiController := openapi.NewDIDApiController(DIDApiService)
DIDExchangeApiService := openapi.NewDIDExchangeApiService(a)
DIDExchangeApiController := openapi.NewDIDExchangeApiController(DIDExchangeApiService)
IssueCredentialApiService := openapi.NewIssueCredentialApiService(a)
IssueCredentialApiController := openapi.NewIssueCredentialApiController(IssueCredentialApiService)
IssueCredentialV2ApiService := openapi.NewIssueCredentialV2ApiService()
IssueCredentialV2ApiController := openapi.NewIssueCredentialV2ApiController(IssueCredentialV2ApiService)
IssueCredentialV3ApiService := openapi.NewIssueCredentialV3ApiService()
IssueCredentialV3ApiController := openapi.NewIssueCredentialV3ApiController(IssueCredentialV3ApiService)
OutOfBandApiService := openapi.NewOutOfBandApiService(a)
OutOfBandApiController := openapi.NewOutOfBandApiController(OutOfBandApiService)
OutOfBandV2ApiService := openapi.NewOutOfBandV2ApiService()
OutOfBandV2ApiController := openapi.NewOutOfBandV2ApiController(OutOfBandV2ApiService)
PresentProofApiService := openapi.NewPresentProofApiService(a)
PresentProofApiController := openapi.NewPresentProofApiController(PresentProofApiService)
PresentProofV2ApiService := openapi.NewPresentProofV2ApiService()
PresentProofV2ApiController := openapi.NewPresentProofV2ApiController(PresentProofV2ApiService)
PresentProofV3ApiService := openapi.NewPresentProofV3ApiService()
PresentProofV3ApiController := openapi.NewPresentProofV3ApiController(PresentProofV3ApiService)
RevocationApiService := openapi.NewRevocationApiService()
RevocationApiController := openapi.NewRevocationApiController(RevocationApiService)
SchemaApiService := openapi.NewSchemaApiService(a)
SchemaApiController := openapi.NewSchemaApiController(SchemaApiService)
StatusApiService := openapi.NewStatusApiService()
StatusApiController := openapi.NewStatusApiController(StatusApiService)
return openapi.NewRouter(
AgentApiController,
ConnectionApiController,
CoordinateMediationApiController,
CredentialApiController,
CredentialDefinitionApiController,
DIDApiController,
DIDExchangeApiController,
IssueCredentialApiController,
IssueCredentialV2ApiController,
IssueCredentialV3ApiController,
OutOfBandApiController,
OutOfBandV2ApiController,
PresentProofApiController,
PresentProofV2ApiController,
PresentProofV3ApiController,
RevocationApiController,
SchemaApiController,
StatusApiController,
)
}
func main() {
port := "9999"
if strings.HasPrefix(os.Args[2], "9") {
port = os.Args[2]
}
log.Printf("Starting server at port %s", port)
a := agent.Init()
a.Login()
log.Printf("Agent login succeeded")
router := createRouter(a)
var handler http.Handler = router
if os.Getenv("FAB_LOG_INCOMING_REQUESTS") == "true" {
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bodyBytes, _ := io.ReadAll(r.Body)
try.To(r.Body.Close())
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
log.Println(r.Method + " " + r.URL.String() + " " + string(bodyBytes))
router.ServeHTTP(w, r)
})
}
server := &http.Server{
Addr: ":" + port,
ReadHeaderTimeout: 3 * time.Second,
Handler: handler,
}
try.To(server.ListenAndServe())
}