Skip to content

Commit 70581a9

Browse files
committed
refactor
1 parent d9c6225 commit 70581a9

28 files changed

+806
-220
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Goscription is a sample of template RESTful API Project
88
Some features & libraries used on this template:
99
1. REST API (**labstack/echo**)
1010
2. Dependency Injection (**uber-go/fx**)
11-
3. Message Streams: Pub/Sub, Kafka, RabbitMQ, etc (**ThreeDotsLabs/watermill**) [Soon]
11+
3. NSQ Messaging (**segmentio/nsq-go**)
1212
4. Custom CLI (**spf13/cobra**)
1313
5. Custom Config File (**spf13/viper**)
1414
6. SQL Generator (**squirrel**)
@@ -17,6 +17,8 @@ Some features & libraries used on this template:
1717
9. Mock Generator (**vektra/mockery**)
1818
10. Custom Logger (**sirupsen/logrus**)
1919
11. Dockerize an Application (**docker**)
20+
12. Circuit Breaker (**hystrix-go/hystrix** && **eapache/go-resiliency**)
21+
13. Message Streams: Pub/Sub, Kafka, RabbitMQ, etc (**ThreeDotsLabs/watermill**) [Soon]
2022

2123
## Installation
2224

@@ -184,5 +186,26 @@ func main() {
184186

185187
You can see more about swag annotation in here: https://github.com/swaggo/swag.
186188

189+
## Benchmark
190+
Using https://github.com/wg/wrk
191+
192+
Script:
193+
```sh
194+
wrk -t8 -c256 -d30s http://localhost:9090/health
195+
```
196+
197+
Output:
198+
```sh
199+
Running 30s test @ http://localhost:9090/health
200+
8 threads and 256 connections
201+
Thread Stats Avg Stdev Max +/- Stdev
202+
Latency 13.17ms 11.67ms 153.74ms 71.04%
203+
Req/Sec 2.82k 660.71 6.40k 69.88%
204+
675770 requests in 30.08s, 150.16MB read
205+
Socket errors: connect 0, read 121, write 0, timeout 0
206+
Requests/sec: 22464.24
207+
Transfer/sec: 4.99MB
208+
```
209+
187210
## Sources
188211
This template is inspired & modified from https://github.com/golangid/menekel

api/docs/docs.go

+147-77
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
1+
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
22
// This file was generated by swaggo/swag
3-
43
package docs
54

65
import (
76
"bytes"
87
"encoding/json"
98
"strings"
9+
"text/template"
1010

11-
"github.com/alecthomas/template"
1211
"github.com/swaggo/swag"
1312
)
1413

1514
var doc = `{
1615
"schemes": {{ marshal .Schemes }},
1716
"swagger": "2.0",
1817
"info": {
19-
"description": "{{.Description}}",
18+
"description": "{{escape .Description}}",
2019
"title": "{{.Title}}",
2120
"termsOfService": "http://swagger.io/terms/",
2221
"contact": {
@@ -33,6 +32,85 @@ var doc = `{
3332
"host": "{{.Host}}",
3433
"basePath": "{{.BasePath}}",
3534
"paths": {
35+
"/address": {
36+
"get": {
37+
"description": "get address",
38+
"consumes": [
39+
"application/json"
40+
],
41+
"produces": [
42+
"application/json"
43+
],
44+
"tags": [
45+
"address"
46+
],
47+
"summary": "Show a Address",
48+
"responses": {
49+
"400": {
50+
"description": "Bad Request",
51+
"schema": {
52+
"$ref": "#/definitions/models.BaseResponse"
53+
}
54+
},
55+
"404": {
56+
"description": "Not Found",
57+
"schema": {
58+
"$ref": "#/definitions/models.BaseResponse"
59+
}
60+
},
61+
"500": {
62+
"description": "Internal Server Error",
63+
"schema": {
64+
"$ref": "#/definitions/models.BaseResponse"
65+
}
66+
}
67+
}
68+
},
69+
"post": {
70+
"description": "insert address",
71+
"consumes": [
72+
"application/json"
73+
],
74+
"produces": [
75+
"application/json"
76+
],
77+
"tags": [
78+
"address"
79+
],
80+
"summary": "Show a Address",
81+
"parameters": [
82+
{
83+
"description": "address",
84+
"name": "address",
85+
"in": "body",
86+
"required": true,
87+
"schema": {
88+
"$ref": "#/definitions/models.Address"
89+
}
90+
}
91+
],
92+
"responses": {
93+
"400": {
94+
"description": "Bad Request",
95+
"schema": {
96+
"$ref": "#/definitions/models.BaseResponse"
97+
}
98+
},
99+
"404": {
100+
"description": "Not Found",
101+
"schema": {
102+
"$ref": "#/definitions/models.BaseResponse"
103+
}
104+
},
105+
"500": {
106+
"description": "Internal Server Error",
107+
"schema": {
108+
"$ref": "#/definitions/models.BaseResponse"
109+
}
110+
}
111+
}
112+
}
113+
},
36114
"/articles": {
37115
"get": {
38116
"description": "get string by ID",
@@ -266,92 +344,36 @@ var doc = `{
266344
}
267345
}
268346
},
269-
"/domains": {
270-
"get": {
271-
"description": "get string by ID",
272-
"consumes": [
273-
"application/json"
274-
],
275-
"produces": [
276-
"application/json"
277-
],
278-
"tags": [
279-
"domains"
280-
],
281-
"summary": "Show a Domains",
282-
"responses": {
283-
"400": {
284-
"description": "Bad Request",
285-
"schema": {
286-
"$ref": "#/definitions/controller.ResponseError"
287-
}
288-
},
289-
"404": {
290-
"description": "Not Found",
291-
"schema": {
292-
"$ref": "#/definitions/controller.ResponseError"
293-
}
294-
},
295-
"500": {
296-
"description": "Internal Server Error",
297-
"schema": {
298-
"$ref": "#/definitions/controller.ResponseError"
299-
}
300-
}
301-
}
302-
}
303-
},
304-
"/domains/available": {
347+
"/health": {
305348
"get": {
306-
"description": "get string by ID",
349+
"description": "get health",
307350
"consumes": [
308351
"application/json"
309352
],
310353
"produces": [
311354
"application/json"
312355
],
313356
"tags": [
314-
"domains"
315-
],
316-
"summary": "Show a Domains Available",
317-
"parameters": [
318-
{
319-
"type": "string",
320-
"description": "domain name",
321-
"name": "domain",
322-
"in": "query",
323-
"required": true
324-
}
357+
"health"
325358
],
359+
"summary": "Show a Health",
326360
"responses": {
327-
"200": {
328-
"description": "OK",
329-
"schema": {
330-
"$ref": "#/definitions/models.DomainAvailableResponse"
331-
},
332-
"headers": {
333-
"Token": {
334-
"type": "string",
335-
"description": "qwerty"
336-
}
337-
}
338-
},
339361
"400": {
340362
"description": "Bad Request",
341363
"schema": {
342-
"$ref": "#/definitions/controller.ResponseError"
364+
"$ref": "#/definitions/models.BaseResponse"
343365
}
344366
},
345367
"404": {
346368
"description": "Not Found",
347369
"schema": {
348-
"$ref": "#/definitions/controller.ResponseError"
370+
"$ref": "#/definitions/models.BaseResponse"
349371
}
350372
},
351373
"500": {
352374
"description": "Internal Server Error",
353375
"schema": {
354-
"$ref": "#/definitions/controller.ResponseError"
376+
"$ref": "#/definitions/models.BaseResponse"
355377
}
356378
}
357379
}
@@ -491,26 +513,67 @@ var doc = `{
491513
}
492514
}
493515
},
494-
"models.DomainAvailableResponse": {
516+
"models.Address": {
495517
"type": "object",
518+
"required": [
519+
"address_full",
520+
"address_title",
521+
"user_id"
522+
],
496523
"properties": {
497-
"available": {
498-
"type": "boolean"
524+
"address_full": {
525+
"type": "string"
499526
},
500-
"currency": {
527+
"address_title": {
501528
"type": "string"
502529
},
503-
"definitive": {
504-
"type": "boolean"
530+
"created_at": {
531+
"type": "string"
505532
},
506-
"domain": {
533+
"created_by": {
507534
"type": "string"
508535
},
509-
"period": {
536+
"district_name": {
537+
"type": "string"
538+
},
539+
"id": {
510540
"type": "integer"
511541
},
512-
"price": {
542+
"primary": {
543+
"type": "boolean"
544+
},
545+
"subdistrict_name": {
546+
"type": "string"
547+
},
548+
"updated_at": {
549+
"type": "string"
550+
},
551+
"updated_by": {
552+
"type": "string"
553+
},
554+
"user_id": {
513555
"type": "integer"
556+
},
557+
"zip_code": {
558+
"type": "string"
559+
}
560+
}
561+
},
562+
"models.BaseResponse": {
563+
"type": "object",
564+
"properties": {
565+
"code": {
566+
"type": "string"
567+
},
568+
"data": {},
569+
"error": {
570+
"type": "array",
571+
"items": {
572+
"type": "string"
573+
}
574+
},
575+
"message": {
576+
"type": "string"
514577
}
515578
}
516579
}
@@ -578,6 +641,13 @@ func (s *s) ReadDoc() string {
578641
a, _ := json.Marshal(v)
579642
return string(a)
580643
},
644+
"escape": func(v interface{}) string {
645+
// escape tabs
646+
str := strings.Replace(v.(string), "\t", "\\t", -1)
647+
// replace " with \", and if that results in \\", replace that with \\\"
648+
str = strings.Replace(str, "\"", "\\\"", -1)
649+
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
650+
},
581651
}).Parse(doc)
582652
if err != nil {
583653
return doc
@@ -592,5 +662,5 @@ func (s *s) ReadDoc() string {
592662
}
593663

594664
func init() {
595-
swag.Register(swag.Name, &s{})
665+
swag.Register("swagger", &s{})
596666
}

0 commit comments

Comments
 (0)