Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create at #216

Merged
merged 20 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ generate: ## Code generation
--go_out=plugins=grpc:. \
pkg/link/link.proto

@protoc -I/usr/local/include -I. \
--gotemplate_out=all=true,template_dir=internal/store/query/template:internal/store/query \
pkg/link/link.proto

@echo "proto generation gRPC-web"
@protoc -I/usr/local/include -I. \
-I=pkg/api/grpc-web \
Expand All @@ -56,9 +60,16 @@ generate: ## Code generation
@echo "Generate go static"
@pkger -o cmd/shortlink

@make fmt

golint: ## Linter for golang
@golangci-lint run

.PHONY: fmt
fmt: ## Format source using gofmt
@echo Apply go fmt
@gofmt -l -s -w cmd pkg internal

gosec: ## Golang security checker
@gosec ./...

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ docker-compose \
| TRACER_URI | localhost:6831 | Tracing addr:host |
| API_TYPE | http-chi | Select: http-chi, gRPC-web, graphql, cloudevents |
| API_PORT | 7070 | API port |
/ MQ_ENABLED | false | Enabled MQ-service |

### Optional

Expand Down
17 changes: 12 additions & 5 deletions cmd/shortlink/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"time"

"github.com/batazor/shortlink/internal/mq/kafka"
"github.com/heptiolabs/healthcheck"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -14,7 +15,6 @@ import (

"github.com/batazor/shortlink/internal/logger"
"github.com/batazor/shortlink/internal/mq"
"github.com/batazor/shortlink/internal/mq/kafka"
"github.com/batazor/shortlink/internal/store"
"github.com/batazor/shortlink/internal/traicing"
"github.com/batazor/shortlink/pkg/api"
Expand Down Expand Up @@ -89,12 +89,19 @@ func (s *Service) initMonitoring() *http.ServeMux {
}

func (s *Service) initMQ(ctx context.Context) {
s.mq = &kafka.Kafka{}
if err := s.mq.Init(ctx); err != nil {
panic(err)
viper.SetDefault("MQ_ENABLED", "false")

if viper.GetBool("MQ_ENABLED") {
s.mq = &kafka.Kafka{}
if err := s.mq.Init(ctx); err != nil {
panic(err)
}

s.log.Info("Run MQ")
return
}

s.log.Info("Run MQ")
s.log.Info("MQ Disabled")
}

// Start - run this a service
Expand Down
57 changes: 54 additions & 3 deletions docs/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,40 @@
"parameters": [
{
"name": "url",
"description": "URL.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "hash",
"description": "Hash by URL + salt.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "describe",
"description": "Describe of link.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "created_at",
"description": "Create at.",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "updated_at",
"description": "Update at.",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
}
],
"tags": [
Expand All @@ -115,21 +134,40 @@
"parameters": [
{
"name": "hash",
"description": "Hash by URL + salt",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "url",
"description": "URL.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "describe",
"description": "Describe of link.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "created_at",
"description": "Create at.",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "updated_at",
"description": "Update at.",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
}
],
"tags": [
Expand All @@ -143,13 +181,26 @@
"type": "object",
"properties": {
"url": {
"type": "string"
"type": "string",
"title": "URL"
},
"hash": {
"type": "string"
"type": "string",
"title": "Hash by URL + salt"
},
"describe": {
"type": "string"
"type": "string",
"title": "Describe of link"
},
"created_at": {
"type": "string",
"format": "date-time",
"title": "Create at"
},
"updated_at": {
"type": "string",
"format": "date-time",
"title": "Update at"
}
}
},
Expand Down
38 changes: 26 additions & 12 deletions docs/shortlink.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "57c4f7c5-785f-4db1-b479-ed96467b152d",
"_postman_id": "194e8458-a108-459d-a37b-a1007abdda53",
"name": "shortlink",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -131,8 +131,11 @@
}
],
"body": {
"mode": "raw",
"raw": "{\"query\": \"{ link(hash: \\\"{{hash}}\\\") {url} }\"}"
"mode": "graphql",
"graphql": {
"query": "{ link(hash: \"{{hash}}\") {url} }",
"variables": ""
}
},
"url": {
"raw": "localhost:7070/api/query",
Expand All @@ -159,8 +162,11 @@
}
],
"body": {
"mode": "raw",
"raw": "{\"query\": \"{ links { url } }\"}"
"mode": "graphql",
"graphql": {
"query": "{ links { url created_at } }",
"variables": ""
}
},
"url": {
"raw": "localhost:7070/api/query",
Expand All @@ -182,13 +188,15 @@
{
"listen": "test",
"script": {
"type": "text/javascript",
"id": "d1818d45-7022-40d7-98e5-e0dbd95ee6cd",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"",
"",
"postman.setGlobalVariable(\"hash\", jsonData.data.createLink.hash);"
]
"postman.setGlobalVariable(\"hash\", jsonData.data.createLink.hash);",
"postman.setEnvironmentVariable(\"hash\", jsonData.data.createLink.hash);"
],
"type": "text/javascript"
}
}
],
Expand All @@ -201,8 +209,11 @@
}
],
"body": {
"mode": "raw",
"raw": "{\"query\":\"mutation createLink { createLink( url: \\\"https://example.com\\\", hash: \\\"\\\", describe: \\\"\\\" ) { url hash describe } }\"}"
"mode": "graphql",
"graphql": {
"query": "mutation createLink { createLink( url: \"https://example.com\", hash: \"\", describe: \"\" ) { url hash describe created_at } }",
"variables": ""
}
},
"url": {
"raw": "localhost:7070/api/query",
Expand All @@ -229,8 +240,11 @@
}
],
"body": {
"mode": "raw",
"raw": "{\"query\":\"mutation deleteLink { deleteLink( hash: \\\"{{hash}}\\\" ) { } }\"}"
"mode": "graphql",
"graphql": {
"query": "mutation deleteLink { deleteLink( hash: \"{{hash}}\" ) { } }",
"variables": ""
}
},
"url": {
"raw": "localhost:7070/api/query",
Expand Down
14 changes: 14 additions & 0 deletions docs/shortlink.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "9cced0d8-a7b2-446d-951f-93e5a3eede48",
"name": "shortlink",
"values": [
{
"key": "hash",
"value": "5888cab",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2019-12-20T10:20:39.742Z",
"_postman_exported_using": "Postman/7.12.0"
}
63 changes: 45 additions & 18 deletions github.com/batazor/shortlink/pkg/link/link.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
go.mongodb.org/mongo-driver v1.2.0
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f
Expand Down
Loading