Skip to content

Commit 6bf9943

Browse files
Merge pull request #23 from getCompass/release_v5.2.0
Release v5.2.0
2 parents 641c246 + 01b7430 commit 6bf9943

File tree

198 files changed

+5654
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+5654
-405
lines changed

go_activity/.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.idea
3+
.gitignore
4+
.golangci.yml
5+
.gitlab-ci.yml
6+
tag.gitlab-ci.yml
7+
run_test.sh
8+
readme.debug

go_activity/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.idea
2+
.DS_Store
3+
main
4+
main.pid
5+
/company_cache
6+
api/conf/conf.json
7+
/api/conf/sharding.json
8+
/api/conf/test_define.json
9+
/dev/_go/*
10+
!/dev/_go/example.go
11+
/logs
12+
/logs/*

go_activity/Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM docker.getcompass.ru/service/go:1.23.2-1
2+
3+
COPY . /app
4+
RUN cd /app && mkdir -p logs && ln -sf /dev/stdout /app/logs/main.log && go build -o activity -mod vendor main.go && chmod +x ./entrypoint.sh
5+
RUN apk del .build-deps
6+
7+
WORKDIR /app
8+
9+
# запускаем
10+
CMD ["sh", "/app/entrypoint.sh"]
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"logging_level": ${LOGGING_LEVEL},
3+
"server_type": "${SERVER_TYPE}",
4+
"tcp_port": ${TCP_PORT},
5+
"grpc_port": ${GRPC_PORT},
6+
"rabbit_queue": "${RABBIT_QUEUE}",
7+
"rabbit_exchange": "${RABBIT_EXCHANGE}",
8+
"get_activity_timeout_ms": ${GET_ACTIVITY_TIMEOUT_MS}
9+
}

go_activity/api/conf/conf.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package conf
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/getCompassUtils/go_base_frame/api/system/flags"
7+
"os"
8+
"path"
9+
"runtime"
10+
"sync/atomic"
11+
"time"
12+
)
13+
14+
// ConfigStruct структура конфига
15+
type ConfigStruct struct {
16+
LoggingLevel int `json:"logging_level"`
17+
ServerType string `json:"server_type"`
18+
19+
TcpPort int64 `json:"tcp_port"`
20+
GrpcPort int64 `json:"grpc_port"`
21+
22+
RabbitQueue string `json:"rabbit_queue"`
23+
RabbitExchange string `json:"rabbit_exchange"`
24+
25+
GetUserTimeoutMs time.Duration `json:"get_activity_timeout_ms"`
26+
}
27+
28+
// переменная содержащая конфигурацию
29+
var configuration atomic.Value
30+
31+
// -------------------------------------------------------
32+
// PUBLIC
33+
// -------------------------------------------------------
34+
35+
// UpdateConfig обновляем конфигурацию
36+
func UpdateConfig() error {
37+
38+
tempPath := flags.ConfDir
39+
if tempPath == "" {
40+
41+
_, b, _, _ := runtime.Caller(0)
42+
tempPath = path.Join(path.Dir(b)) // nosemgrep
43+
}
44+
45+
// сохраняем конфигурацию
46+
decodedInfo, err := getConfigFromFile(tempPath + "/conf.json")
47+
if err != nil {
48+
return err
49+
}
50+
51+
// записываем конфигурацию в хранилище
52+
configuration.Store(decodedInfo)
53+
54+
return nil
55+
}
56+
57+
// получаем конфиг из файла
58+
func getConfigFromFile(path string) (ConfigStruct, error) {
59+
60+
// открываем файл с конфигурацией
61+
file, err := os.Open(path)
62+
if err != nil {
63+
return ConfigStruct{}, fmt.Errorf("unable read file conf.json, error: %v", err)
64+
}
65+
66+
// считываем информацию из файла в переменную
67+
decoder := json.NewDecoder(file)
68+
var decodedInfo ConfigStruct
69+
err = decoder.Decode(&decodedInfo)
70+
if err != nil {
71+
return ConfigStruct{}, fmt.Errorf("unable decode file conf.json, error: %v", err)
72+
}
73+
74+
// закрываем файл
75+
_ = file.Close()
76+
77+
return decodedInfo, nil
78+
}
79+
80+
// GetConfig получаем конфигурацию custom
81+
func GetConfig() ConfigStruct {
82+
83+
// получаем конфиг
84+
config := configuration.Load()
85+
86+
// если конфига еще нет
87+
if config == nil {
88+
89+
// обновляем конфиг
90+
err := UpdateConfig()
91+
if err != nil {
92+
panic(err)
93+
}
94+
95+
// подгружаем новый
96+
config = configuration.Load()
97+
}
98+
99+
return config.(ConfigStruct)
100+
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"mysql": {
3+
"pivot_user_10m": {
4+
"db": "pivot_user_10m",
5+
"mysql": {
6+
"host": "${MYSQL_HOST}:${MYSQL_PORT}",
7+
"user": "${MYSQL_USER}",
8+
"pass": "${MYSQL_PASS}",
9+
"ssl": false,
10+
"max_connections": 50
11+
},
12+
"schemas": {}
13+
},
14+
"pivot_user_20m": {
15+
"db": "pivot_user_20m",
16+
"mysql": {
17+
"host": "${MYSQL_HOST}:${MYSQL_PORT}",
18+
"user": "${MYSQL_USER}",
19+
"pass": "${MYSQL_PASS}",
20+
"ssl": false,
21+
"max_connections": 50
22+
},
23+
"schemas": {}
24+
},
25+
"pivot_user_30m": {
26+
"db": "pivot_user_30m",
27+
"mysql": {
28+
"host": "${MYSQL_HOST}:${MYSQL_PORT}",
29+
"user": "${MYSQL_USER}",
30+
"pass": "${MYSQL_PASS}",
31+
"ssl": false,
32+
"max_connections": 50
33+
},
34+
"schemas": {}
35+
}
36+
},
37+
"rabbit": {
38+
"local": {
39+
"host": "${RABBIT_HOST}",
40+
"port": "${RABBIT_PORT}",
41+
"user": "${RABBIT_USER}",
42+
"pass": "${RABBIT_PASS}"
43+
},
44+
"bus": {
45+
"host": "${RABBIT_HOST}",
46+
"port": "${RABBIT_PORT}",
47+
"user": "${RABBIT_USER}",
48+
"pass": "${RABBIT_PASS}"
49+
}
50+
},
51+
"go": {}
52+
}

go_activity/api/conf/sharding.go

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package conf
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/getCompassUtils/go_base_frame/api/system/flags"
7+
"os"
8+
"path"
9+
"runtime"
10+
"sync/atomic"
11+
)
12+
13+
// ShardingStruct структура файла sharding.json
14+
type ShardingStruct struct {
15+
Mysql map[string]MysqlShardingStruct `json:"mysql,omitempty"`
16+
Rabbit map[string]RabbitShardingStruct `json:"rabbit,omitempty"`
17+
Go map[string]GoShardingStruct `json:"go,omitempty"`
18+
}
19+
20+
// MysqlShardingStruct структура mysql шардом
21+
type MysqlShardingStruct struct {
22+
Db string `json:"db"`
23+
Mysql struct {
24+
Host string `json:"host"`
25+
User string `json:"user"`
26+
Pass string `json:"pass"`
27+
Ssl bool `json:"ssl"`
28+
MaxConnections int `json:"max_connections"`
29+
} `json:"mysql"`
30+
Schemas map[string]string `json:"schemas"`
31+
}
32+
33+
// RabbitShardingStruct структура rabbit шардов
34+
type RabbitShardingStruct struct {
35+
Host string `json:"host"`
36+
Port string `json:"port"`
37+
User string `json:"user"`
38+
Pass string `json:"pass"`
39+
}
40+
41+
// GoShardingStruct структура go шардов
42+
type GoShardingStruct struct {
43+
Host string `json:"host,omitempty"`
44+
Port string `json:"port,omitempty"`
45+
Nodes []GoNodeShardingStruct `json:"nodes,omitempty"`
46+
}
47+
48+
// GoNodeShardingStruct структура go ноды
49+
type GoNodeShardingStruct struct {
50+
Id int64 `json:"id"`
51+
Host string `json:"host"`
52+
Port string `json:"port"`
53+
}
54+
55+
// -------------------------------------------------------
56+
// пакет получения sharding конфигурации
57+
// -------------------------------------------------------
58+
59+
// переменная содержащая конфигурацию
60+
var shardingConfig atomic.Value
61+
62+
// -------------------------------------------------------
63+
// PUBLIC
64+
// -------------------------------------------------------
65+
66+
// UpdateShardingConfig обновляем конфигурацию
67+
func UpdateShardingConfig() error {
68+
69+
tempPath := flags.ConfDir
70+
if tempPath == "" {
71+
72+
_, b, _, _ := runtime.Caller(0)
73+
tempPath = path.Join(path.Dir(b)) // nosemgrep
74+
}
75+
76+
// сохраняем конфигурацию
77+
decodedInfo, err := getShardingConfigFromFile(tempPath + "/sharding.json")
78+
if err != nil {
79+
return err
80+
}
81+
82+
shardingConfig.Store(decodedInfo)
83+
84+
return nil
85+
}
86+
87+
// получаем конфиг из файла
88+
func getShardingConfigFromFile(path string) (ShardingStruct, error) {
89+
90+
// открываем файл с конфигурацией
91+
file, err := os.Open(path)
92+
if err != nil {
93+
return ShardingStruct{}, fmt.Errorf("unable read file sharding.json, error: %v", err)
94+
}
95+
96+
// считываем информацию из файла в переменную
97+
decoder := json.NewDecoder(file)
98+
var decodedInfo ShardingStruct
99+
err = decoder.Decode(&decodedInfo)
100+
if err != nil {
101+
return ShardingStruct{}, fmt.Errorf("unable decode file sharding.json, error: %v", err)
102+
}
103+
104+
// закрываем файл
105+
_ = file.Close()
106+
107+
return decodedInfo, nil
108+
}
109+
110+
// GetShardingConfig получаем конфигурацию custom
111+
func GetShardingConfig() ShardingStruct {
112+
113+
config := shardingConfig.Load()
114+
if config == nil {
115+
116+
err := UpdateShardingConfig()
117+
if err != nil {
118+
panic(err)
119+
}
120+
121+
config = shardingConfig.Load()
122+
}
123+
124+
return config.(ShardingStruct)
125+
}

go_activity/api/conf/test.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)