Skip to content

Commit b886db3

Browse files
committed
[deps] move reusable API parts to client-go
1 parent 694460b commit b886db3

File tree

9 files changed

+23
-69
lines changed

9 files changed

+23
-69
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ module github.com/android-sms-gateway/ca
33
go 1.23.2
44

55
require (
6+
github.com/android-sms-gateway/client-go v1.5.0
67
github.com/go-playground/validator/v10 v10.23.0
78
github.com/gofiber/contrib/fiberzap/v2 v2.1.4
89
github.com/gofiber/fiber/v2 v2.52.6
910
github.com/gofiber/swagger v1.1.1
11+
github.com/golang-queue/queue v0.3.0
1012
github.com/jaevor/go-nanoid v1.4.0
1113
github.com/joho/godotenv v1.5.1
1214
github.com/kelseyhightower/envconfig v1.4.0
@@ -28,7 +30,6 @@ require (
2830
github.com/go-openapi/swag v0.23.0 // indirect
2931
github.com/go-playground/locales v0.14.1 // indirect
3032
github.com/go-playground/universal-translator v0.18.1 // indirect
31-
github.com/golang-queue/queue v0.3.0 // indirect
3233
github.com/google/uuid v1.6.0 // indirect
3334
github.com/josharian/intern v1.0.0 // indirect
3435
github.com/jpillora/backoff v1.0.0 // indirect
@@ -40,7 +41,6 @@ require (
4041
github.com/mattn/go-runewidth v0.0.16 // indirect
4142
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
4243
github.com/rivo/uniseg v0.4.7 // indirect
43-
github.com/stretchr/testify v1.10.0 // indirect
4444
github.com/swaggo/files/v2 v2.0.2 // indirect
4545
github.com/tinylib/msgp v1.2.5 // indirect
4646
github.com/valyala/bytebufferpool v1.0.0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
22
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
3+
github.com/android-sms-gateway/client-go v1.5.0 h1:CDREtWU2Z85dW7JcsW3a+vKZkj9g2Buq8vlrnEdGaoE=
4+
github.com/android-sms-gateway/client-go v1.5.0/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
35
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
46
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
7+
github.com/appleboy/com v0.2.1 h1:dHAHauX3eYDuheAahI83HIGFxpi0SEb2ZAu9EZ9hbUM=
8+
github.com/appleboy/com v0.2.1/go.mod h1:kByEI3/vzI5GM1+O5QdBHLsXaOsmFsJcOpCSgASi4sg=
59
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
610
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
711
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@@ -99,6 +103,8 @@ go.uber.org/fx v1.23.0 h1:lIr/gYWQGfTwGcSXWXu4vP5Ws6iqnNEIY+F/aFzCKTg=
99103
go.uber.org/fx v1.23.0/go.mod h1:o/D9n+2mLP6v1EG+qsdT1O8wKopYAsqZasju97SDFCU=
100104
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
101105
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
106+
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
107+
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
102108
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
103109
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
104110
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=

internal/api/csr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"errors"
55

66
"github.com/android-sms-gateway/ca/internal/csr"
7-
"github.com/android-sms-gateway/ca/pkg/client"
87
"github.com/android-sms-gateway/ca/pkg/core/handler"
8+
"github.com/android-sms-gateway/client-go/ca"
99
"github.com/go-playground/validator/v10"
1010
"github.com/gofiber/fiber/v2"
1111
"go.uber.org/zap"
@@ -18,7 +18,7 @@ type csrHandler struct {
1818
}
1919

2020
func (c *csrHandler) submit(ctx *fiber.Ctx) error {
21-
req := client.PostCSRRequest{}
21+
req := ca.PostCSRRequest{}
2222
if err := c.BodyParserValidator(ctx, &req); err != nil {
2323
return err
2424
}
@@ -28,7 +28,7 @@ func (c *csrHandler) submit(ctx *fiber.Ctx) error {
2828
return err
2929
}
3030

31-
return ctx.JSON(client.PostCSRResponse{
31+
return ctx.JSON(ca.PostCSRResponse{
3232
RequestID: res.ID(),
3333
Status: res.Status(),
3434
Message: res.Status().Description(),
@@ -44,7 +44,7 @@ func (c *csrHandler) status(ctx *fiber.Ctx) error {
4444
return err
4545
}
4646

47-
return ctx.JSON(client.GetCSRStatusResponse{
47+
return ctx.JSON(ca.GetCSRStatusResponse{
4848
RequestID: res.ID(),
4949
Status: res.Status(),
5050
Message: res.Status().Description(),

internal/csr/domain.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package csr
33
import (
44
"encoding/json"
55

6-
"github.com/android-sms-gateway/ca/pkg/client"
6+
"github.com/android-sms-gateway/client-go/ca"
77
)
88

99
type CSR struct {
@@ -42,12 +42,12 @@ func (c CSR) toMap() map[string]string {
4242
type CSRStatus struct {
4343
CSR
4444
id string
45-
status client.CSRStatus
45+
status ca.CSRStatus
4646
certificate string
4747
reason string
4848
}
4949

50-
func NewCSRStatus(id string, content string, metadata map[string]string, status client.CSRStatus, certificate string, reason string) CSRStatus {
50+
func NewCSRStatus(id string, content string, metadata map[string]string, status ca.CSRStatus, certificate string, reason string) CSRStatus {
5151
return CSRStatus{
5252
CSR: CSR{
5353
content: content,
@@ -64,7 +64,7 @@ func (c CSRStatus) ID() string {
6464
return c.id
6565
}
6666

67-
func (c CSRStatus) Status() client.CSRStatus {
67+
func (c CSRStatus) Status() ca.CSRStatus {
6868
return c.status
6969
}
7070

internal/csr/repository.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"time"
99

10-
"github.com/android-sms-gateway/ca/pkg/client"
10+
"github.com/android-sms-gateway/client-go/ca"
1111
"github.com/redis/go-redis/v9"
1212
)
1313

@@ -22,7 +22,7 @@ type repository struct {
2222
}
2323

2424
func (r *repository) Insert(ctx context.Context, requestId string, csr CSR) error {
25-
res := r.redis.HSetNX(ctx, keyStatus, requestId, string(client.CSRStatusPending))
25+
res := r.redis.HSetNX(ctx, keyStatus, requestId, string(ca.CSRStatusPending))
2626
if err := res.Err(); err != nil {
2727
return fmt.Errorf("failed to create csr: %w", err)
2828
}
@@ -73,15 +73,15 @@ func (r *repository) Get(ctx context.Context, requestId string) (CSRStatus, erro
7373
return CSRStatus{}, fmt.Errorf("failed to get csr: %w", err)
7474
}
7575

76-
return NewCSRStatus(requestId, res["content"], metadata, client.CSRStatus(status), res["certificate"], res["reason"]), nil
76+
return NewCSRStatus(requestId, res["content"], metadata, ca.CSRStatus(status), res["certificate"], res["reason"]), nil
7777
}
7878

7979
func (r *repository) SetCertificate(ctx context.Context, requestId string, certificate string) error {
8080
key := "csr:" + requestId
8181

8282
_, err := r.redis.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
8383
pipe.HSet(ctx, key, "certificate", certificate)
84-
pipe.HSet(ctx, keyStatus, requestId, string(client.CSRStatusApproved))
84+
pipe.HSet(ctx, keyStatus, requestId, string(ca.CSRStatusApproved))
8585

8686
return nil
8787
})

internal/csr/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/android-sms-gateway/ca/pkg/client"
15+
"github.com/android-sms-gateway/client-go/ca"
1616
"github.com/golang-queue/queue"
1717
"github.com/golang-queue/queue/core"
1818
"github.com/jaevor/go-nanoid"
@@ -62,7 +62,7 @@ func (s *Service) Create(ctx context.Context, csr CSR) (CSRStatus, error) {
6262
s.log.Error("failed to queue csr", zap.Error(err))
6363
}
6464

65-
return NewCSRStatus(id, csr.content, csr.metadata, client.CSRStatusPending, "", ""), nil
65+
return NewCSRStatus(id, csr.content, csr.metadata, ca.CSRStatusPending, "", ""), nil
6666
}
6767

6868
func (s *Service) Get(ctx context.Context, id string) (CSRStatus, error) {
@@ -83,7 +83,7 @@ func (s *Service) process(ctx context.Context, m core.TaskMessage) error {
8383
return err
8484
}
8585

86-
if res.Status() != client.CSRStatusPending {
86+
if res.Status() != ca.CSRStatusPending {
8787
return nil
8888
}
8989

pkg/client/enums.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkg/client/requests.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

pkg/client/responses.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)