Skip to content

Commit

Permalink
Merge pull request #5 from kecci/feature/address
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
kecci authored Jul 26, 2022
2 parents 64f1149 + 70581a9 commit 9315981
Show file tree
Hide file tree
Showing 32 changed files with 806 additions and 545 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Goscription is a sample of template RESTful API Project
Some features & libraries used on this template:
1. REST API (**labstack/echo**)
2. Dependency Injection (**uber-go/fx**)
3. Message Streams: Pub/Sub, Kafka, RabbitMQ, etc (**ThreeDotsLabs/watermill**) [Soon]
3. NSQ Messaging (**segmentio/nsq-go**)
4. Custom CLI (**spf13/cobra**)
5. Custom Config File (**spf13/viper**)
6. SQL Generator (**squirrel**)
Expand All @@ -17,6 +17,8 @@ Some features & libraries used on this template:
9. Mock Generator (**vektra/mockery**)
10. Custom Logger (**sirupsen/logrus**)
11. Dockerize an Application (**docker**)
12. Circuit Breaker (**hystrix-go/hystrix** && **eapache/go-resiliency**)
13. Message Streams: Pub/Sub, Kafka, RabbitMQ, etc (**ThreeDotsLabs/watermill**) [Soon]

## Installation

Expand Down Expand Up @@ -184,5 +186,26 @@ func main() {

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

## Benchmark
Using https://github.com/wg/wrk

Script:
```sh
wrk -t8 -c256 -d30s http://localhost:9090/health
```

Output:
```sh
Running 30s test @ http://localhost:9090/health
8 threads and 256 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 13.17ms 11.67ms 153.74ms 71.04%
Req/Sec 2.82k 660.71 6.40k 69.88%
675770 requests in 30.08s, 150.16MB read
Socket errors: connect 0, read 121, write 0, timeout 0
Requests/sec: 22464.24
Transfer/sec: 4.99MB
```

## Sources
This template is inspired & modified from https://github.com/golangid/menekel
224 changes: 147 additions & 77 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag

package docs

import (
"bytes"
"encoding/json"
"strings"
"text/template"

"github.com/alecthomas/template"
"github.com/swaggo/swag"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"termsOfService": "http://swagger.io/terms/",
"contact": {
Expand All @@ -33,6 +32,85 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/address": {
"get": {
"description": "get address",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"address"
],
"summary": "Show a Address",
"responses": {
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
}
}
},
"post": {
"description": "insert address",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"address"
],
"summary": "Show a Address",
"parameters": [
{
"description": "address",
"name": "address",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.Address"
}
}
],
"responses": {
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.BaseResponse"
}
}
}
}
},
"/articles": {
"get": {
"description": "get string by ID",
Expand Down Expand Up @@ -266,92 +344,36 @@ var doc = `{
}
}
},
"/domains": {
"get": {
"description": "get string by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"domains"
],
"summary": "Show a Domains",
"responses": {
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
}
}
}
}
},
"/domains/available": {
"/health": {
"get": {
"description": "get string by ID",
"description": "get health",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"domains"
],
"summary": "Show a Domains Available",
"parameters": [
{
"type": "string",
"description": "domain name",
"name": "domain",
"in": "query",
"required": true
}
"health"
],
"summary": "Show a Health",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.DomainAvailableResponse"
},
"headers": {
"Token": {
"type": "string",
"description": "qwerty"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
"$ref": "#/definitions/models.BaseResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
"$ref": "#/definitions/models.BaseResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/controller.ResponseError"
"$ref": "#/definitions/models.BaseResponse"
}
}
}
Expand Down Expand Up @@ -491,26 +513,67 @@ var doc = `{
}
}
},
"models.DomainAvailableResponse": {
"models.Address": {
"type": "object",
"required": [
"address_full",
"address_title",
"user_id"
],
"properties": {
"available": {
"type": "boolean"
"address_full": {
"type": "string"
},
"currency": {
"address_title": {
"type": "string"
},
"definitive": {
"type": "boolean"
"created_at": {
"type": "string"
},
"domain": {
"created_by": {
"type": "string"
},
"period": {
"district_name": {
"type": "string"
},
"id": {
"type": "integer"
},
"price": {
"primary": {
"type": "boolean"
},
"subdistrict_name": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"updated_by": {
"type": "string"
},
"user_id": {
"type": "integer"
},
"zip_code": {
"type": "string"
}
}
},
"models.BaseResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"data": {},
"error": {
"type": "array",
"items": {
"type": "string"
}
},
"message": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -578,6 +641,13 @@ func (s *s) ReadDoc() string {
a, _ := json.Marshal(v)
return string(a)
},
"escape": func(v interface{}) string {
// escape tabs
str := strings.Replace(v.(string), "\t", "\\t", -1)
// replace " with \", and if that results in \\", replace that with \\\"
str = strings.Replace(str, "\"", "\\\"", -1)
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
},
}).Parse(doc)
if err != nil {
return doc
Expand All @@ -592,5 +662,5 @@ func (s *s) ReadDoc() string {
}

func init() {
swag.Register(swag.Name, &s{})
swag.Register("swagger", &s{})
}
Loading

0 comments on commit 9315981

Please sign in to comment.