-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
25 changed files
with
1,195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Customer service | ||
## What it is? | ||
|
||
This example is taken directly from the vshard repository example. A go service was written on top. | ||
Includes only 2 endpoints (see [swagger](go-service/docs/swagger.yaml)): count, record sales information. | ||
Only a few changes have been made: | ||
|
||
- slightly modified Makefile | ||
- by default, the example was created for fault tolerance according to Raft (only for replicaset 1, since there are 3 instances) | ||
- the number of buckets is set to 10k | ||
- minor fixes to critical errors (for example, the “transaction” attempt was replaced by box.atomic) | ||
- added 1 more instance to replicaset 1 so that raft could select a new master | ||
## How to start? | ||
|
||
1. Start the cluster | ||
|
||
```sh | ||
$ cd tarantool | ||
$ make start | ||
``` | ||
|
||
2. Launch the service | ||
```sh | ||
$ cd go-service # from the customer directory | ||
$ make start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Customer service | ||
## Что это такое? | ||
|
||
Этот пример взят напрямую из примера репозитория vshard. Поверх был написан сервис на go. | ||
Включает лишь 2 эндпоинта (см. [swagger](go-service/docs/swagger.yaml)): считать, записать информацию о продаже. | ||
Допущены лишь несколько изменений: | ||
|
||
- несколько модифицирован Makefile | ||
- по умолчанию пример создан для отказоустойчивости по Raft(только для репликасета 1, поскольку там 3 инстанса) | ||
- количество бакетов установлено в 10k | ||
- минорные исправления критических ошибок (например попытка "транзакции" заменена на box.atomic) | ||
- добавлен еще 1 инстанс в репликасет 1, чтобы raft мог выбрать нового мастера | ||
## Как запустить? | ||
|
||
1. Запускаем кластер | ||
|
||
```sh | ||
$ cd tarantool | ||
$ make start | ||
``` | ||
|
||
2. Запускаем сервис | ||
```sh | ||
$ cd go-service # из директории customer | ||
$ make start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: install-swaggo | ||
install-swaggo: | ||
ifeq ($(wildcard $(SWAGGO_BIN)),) | ||
$(info #Downloading swaggo latest) | ||
go install github.com/swaggo/swag/cmd/swag@latest | ||
endif | ||
|
||
start: | ||
go run main.go config.yaml | ||
|
||
# генерирует свагер | ||
.PHONY: generate | ||
generate: install-swaggo | ||
swag init -g main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
listener: | ||
address: :8096 | ||
routers: | ||
addrs: | ||
- "127.0.0.1:12002" | ||
storage: | ||
direct: true | ||
total_bucket_count: 10000 | ||
topology: | ||
clusters: | ||
storage_1: | ||
replicaset_uuid: cbf06940-0790-498b-948d-042b62cf3d29 | ||
storage_2: | ||
replicaset_uuid: ac522f65-aa94-4134-9f64-51ee384f1a54 | ||
instances: | ||
storage_1_a: | ||
cluster: storage_1 | ||
box: | ||
listen: '127.0.0.1:3301' | ||
instance_uuid: '6E35AC64-1241-0001-0001-000000000000' | ||
storage_1_b: | ||
cluster: storage_1 | ||
box: | ||
listen: '127.0.0.1:3302' | ||
instance_uuid: '6E35AC64-1241-0001-0002-000000000000' | ||
storage_1_c: | ||
cluster: storage_1 | ||
box: | ||
listen: '127.0.0.1:3305' | ||
instance_uuid: '6E35AC64-1241-0001-0003-000000000000' | ||
storage_2_a: | ||
cluster: storage_2 | ||
box: | ||
listen: '127.0.0.1:3303' | ||
instance_uuid: '6E35AC64-1241-0002-0001-000000000000' | ||
storage_2_b: | ||
cluster: storage_2 | ||
box: | ||
listen: '127.0.0.1:3304' | ||
instance_uuid: '6E35AC64-1241-0002-0002-000000000000' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Package docs Code generated by swaggo/swag. DO NOT EDIT | ||
package docs | ||
|
||
import "github.com/swaggo/swag" | ||
|
||
const docTemplate = `{ | ||
"schemes": {{ marshal .Schemes }}, | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "{{escape .Description}}", | ||
"title": "{{.Title}}", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": { | ||
"name": "API Support", | ||
"url": "http://quedafoe.ru", | ||
"email": "djassange@ya.ru" | ||
}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": { | ||
"/customer_add": { | ||
"post": { | ||
"description": "Todo", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"Set" | ||
], | ||
"summary": "Todo", | ||
"parameters": [ | ||
{ | ||
"description": "Обязательно не должно быть пустым", | ||
"name": "Request", | ||
"in": "body", | ||
"required": true, | ||
"schema": { | ||
"$ref": "#/definitions/main.CustomerAddRequest" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "ok", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/customer_lookup": { | ||
"get": { | ||
"description": "Todo", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"Get" | ||
], | ||
"summary": "Todo", | ||
"parameters": [ | ||
{ | ||
"type": "string", | ||
"description": "id of customer", | ||
"name": "id", | ||
"in": "query" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/main.CustomerLookupResponse" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"main.CustomerAddRequest": { | ||
"type": "object", | ||
"properties": { | ||
"accounts": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"account_id": { | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"customer_id": { | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"main.CustomerLookupResponse": { | ||
"type": "object", | ||
"properties": { | ||
"accounts": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"account_id": { | ||
"type": "integer" | ||
}, | ||
"balance": { | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"customer_id": { | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}` | ||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it | ||
var SwaggerInfo = &swag.Spec{ | ||
Version: "1.0", | ||
Host: "localhost:8096", | ||
BasePath: "", | ||
Schemes: []string{}, | ||
Title: "Example customer service Swagger API", | ||
Description: "Just example :)", | ||
InfoInstanceName: "swagger", | ||
SwaggerTemplate: docTemplate, | ||
LeftDelim: "{{", | ||
RightDelim: "}}", | ||
} | ||
|
||
func init() { | ||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) | ||
} |
Oops, something went wrong.