tebakaja commited on
Commit
0503b31
1 Parent(s): 4bfd745

update: add docker and actions config

Browse files
Files changed (6) hide show
  1. .dockerignore +20 -0
  2. Dockerfile +2 -15
  3. Makefile +33 -8
  4. postman/.gitkeep +0 -0
  5. proxy/crypto/list_service.go +1 -0
  6. proxy/utils.go +35 -37
.dockerignore CHANGED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # git and github
2
+ /.github
3
+ README.md
4
+
5
+ # vscode
6
+ /.vscode
7
+
8
+ # proxies
9
+ /nginx
10
+ /traefik
11
+ /haproxy
12
+
13
+ # compose
14
+ docker-compose.yaml
15
+
16
+ # make
17
+ Makefile
18
+
19
+ # postman
20
+ /postman
Dockerfile CHANGED
@@ -1,28 +1,15 @@
1
- # --- Build stage ---
2
- FROM golang:1.20 as builder
3
 
4
  LABEL creator="qywok"
5
 
6
  WORKDIR /app
7
 
8
  COPY go.mod go.sum ./
9
-
10
  RUN go mod download
11
 
12
  COPY . .
13
 
14
- RUN go build -o main .
15
-
16
- # --- Deploy stage ---
17
- FROM alpine:latest
18
-
19
- WORKDIR /app
20
-
21
- RUN adduser -D -u 1000 user
22
- USER user
23
- ENV PATH="/home/user/.local/bin:$PATH"
24
-
25
- COPY --from=builder /app/main /app/main
26
 
27
  EXPOSE 7860
28
 
 
1
+ FROM golang:1.20
 
2
 
3
  LABEL creator="qywok"
4
 
5
  WORKDIR /app
6
 
7
  COPY go.mod go.sum ./
 
8
  RUN go mod download
9
 
10
  COPY . .
11
 
12
+ RUN go build -o main
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  EXPOSE 7860
15
 
Makefile CHANGED
@@ -1,4 +1,5 @@
1
- ENDPOINT=http://192.168.137.1:7860
 
2
 
3
  start:
4
  go run main.go
@@ -20,26 +21,50 @@ traefik-test:
20
  --api.insecure=false
21
 
22
  stock-list-test:
23
- curl -X GET $(ENDPOINT)/stock/lists
24
 
25
  stock-prediction-test:
26
- curl -X POST $(ENDPOINT)/stock/prediction \
27
  -H "Content-Type: application/json" \
28
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
29
 
30
  crypto-list-test:
31
- curl -X GET $(ENDPOINT)/crypto/lists
32
 
33
  crypto-prediction-test:
34
- curl -X POST $(ENDPOINT)/crypto/prediction \
35
  -H "Content-Type: application/json" \
36
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
37
 
38
  natcurr-list-test:
39
- curl -X GET $(ENDPOINT)/national-currency/lists
40
 
41
  natcurr-prediction-test:
42
- curl -X POST $(ENDPOINT)/national-currency/prediction \
43
  -H "Content-Type: application/json" \
44
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
45
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ DEV_ENDPOINT=http://192.168.137.1:7860
2
+ PROD_ENDPOINT=https://qywok-tebakaja-proxy-space-0.hf.space
3
 
4
  start:
5
  go run main.go
 
21
  --api.insecure=false
22
 
23
  stock-list-test:
24
+ curl -X GET $(DEV_ENDPOINT)/stock/lists
25
 
26
  stock-prediction-test:
27
+ curl -X POST $(DEV_ENDPOINT)/stock/prediction \
28
  -H "Content-Type: application/json" \
29
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
30
 
31
  crypto-list-test:
32
+ curl -X GET $(DEV_ENDPOINT)/crypto/lists
33
 
34
  crypto-prediction-test:
35
+ curl -X POST $(DEV_ENDPOINT)/crypto/prediction \
36
  -H "Content-Type: application/json" \
37
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
38
 
39
  natcurr-list-test:
40
+ curl -X GET $(DEV_ENDPOINT)/national-currency/lists
41
 
42
  natcurr-prediction-test:
43
+ curl -X POST $(DEV_ENDPOINT)/national-currency/prediction \
44
  -H "Content-Type: application/json" \
45
  -d "{\"days\": 2, \"currency\": \"BTC-USD\"}"
46
+
47
+
48
+ stock-list-prod:
49
+ curl -X GET $(PROD_ENDPOINT)/stock/lists
50
+
51
+ stock-prediction-prod:
52
+ curl -X POST $(PROD_ENDPOINT)/stock/prediction \
53
+ -H "Content-Type: application/json" \
54
+ -d "{\"days\": 7, \"currency\": \"BTC-USD\"}"
55
+
56
+ crypto-list-prod:
57
+ curl -X GET $(PROD_ENDPOINT)/crypto/lists
58
+
59
+ crypto-prediction-prod:
60
+ curl -X POST $(PROD_ENDPOINT)/crypto/prediction \
61
+ -H "Content-Type: application/json" \
62
+ -d "{\"days\": 7, \"currency\": \"BTC-USD\"}"
63
+
64
+ natcurr-list-prod:
65
+ curl -X GET $(PROD_ENDPOINT)/national-currency/lists
66
+
67
+ natcurr-prediction-prod:
68
+ curl -X POST $(PROD_ENDPOINT)/national-currency/prediction \
69
+ -H "Content-Type: application/json" \
70
+ -d "{\"days\": 7, \"currency\": \"BTC-USD\"}"
postman/.gitkeep ADDED
File without changes
proxy/crypto/list_service.go CHANGED
@@ -5,6 +5,7 @@ import (
5
  "context"
6
  "net/http"
7
  "encoding/json"
 
8
  proxy "tebakaja_lb_proxy/proxy"
9
  )
10
 
 
5
  "context"
6
  "net/http"
7
  "encoding/json"
8
+
9
  proxy "tebakaja_lb_proxy/proxy"
10
  )
11
 
proxy/utils.go CHANGED
@@ -1,45 +1,43 @@
1
  package proxy
2
 
3
- import "time"
4
 
5
- func GetEndpointByRestService(svc_name string) string {
6
- second := time.Now().Second()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- var divisorToString map[int]string
 
9
  switch svc_name {
10
- case "crypto":
11
- divisorToString = map[int]string{
12
- 9: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
13
- 7: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
14
- 5: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
15
- 3: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
16
- 2: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
17
- }
18
- case "national":
19
- divisorToString = map[int]string{
20
- 9: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
21
- 7: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
22
- 5: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
23
- 3: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
24
- 2: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
25
- }
26
- default:
27
- divisorToString = map[int]string{
28
- 9: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
29
- 7: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
30
- 5: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
31
- 3: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
32
- 2: "https://qywok-cryptocurrency-prediction.hf.space/crypto",
33
- }
34
  }
35
 
36
- var result string
37
- for divisor, str := range divisorToString {
38
- if (second % divisor) == 0 {
39
- result += str
40
- break
41
- }
42
- }
43
 
44
- return result
45
- }
 
1
  package proxy
2
 
3
+ import "math/rand"
4
 
5
+ var serviceUrls = map[string][]string{
6
+ "crypto": {
7
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
8
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
9
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
10
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
11
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
12
+ },
13
+ "national": {
14
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
15
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
16
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
17
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
18
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
19
+ },
20
+ "stock": {
21
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
22
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
23
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
24
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
25
+ "https://qywok-cryptocurrency-prediction.hf.space/crypto",
26
+ },
27
+ }
28
 
29
+ func GetEndpointByRestService(svc_name string) string {
30
+ var selectedUrls []string
31
  switch svc_name {
32
+ case "crypto":
33
+ selectedUrls = serviceUrls["crypto"]
34
+ case "national":
35
+ selectedUrls = serviceUrls["national"]
36
+ default:
37
+ selectedUrls = serviceUrls["stock"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
+ randomIndex := rand.Intn(len(selectedUrls))
 
 
 
 
 
 
41
 
42
+ return selectedUrls[randomIndex]
43
+ }