Compare commits
167 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 53d765d723 | |||
| d5eb16b8cd | |||
| 11900eeecd | |||
| 4f9ef33ab1 | |||
| be77803d96 | |||
| 4fbc0a35a7 | |||
| ba94a1d17f | |||
| fb2ba22f72 | |||
| dede386e8b | |||
| 7fa00f323f | |||
| 65105d6982 | |||
| 2ac68aed86 | |||
| bc1b0ff731 | |||
| e97a13d1e8 | |||
| e0d270a2eb | |||
| b829092503 | |||
| e16021ee49 | |||
| 69797a214f | |||
| 53e2d49e36 | |||
| f2ab6a94d5 | |||
| 1954182e1c | |||
| b5852a3e61 | |||
| 0456346b45 | |||
| e6b03fdd02 | |||
| 1018e24060 | |||
| ebef6e138d | |||
| 7bd8f754d8 | |||
| 43574a1d1c | |||
| f130eaedd7 | |||
| 8394feaec7 | |||
|
|
68e6e3ef55 | ||
|
|
feff40bf55 | ||
| eb1e8a9cb0 | |||
| 2c797164e0 | |||
| 7725e5dd65 | |||
| 07c0cd6f2e | |||
| d29bd0810b | |||
| b62c0e5a8c | |||
| a9eb0d0732 | |||
| 92b84685c9 | |||
| cd6e62e3bc | |||
| 7cf2d91fd8 | |||
| 936982731d | |||
| 33759c87db | |||
| 974f82e9be | |||
| d7dc75c18f | |||
| c62c63249c | |||
| 6c290eb66b | |||
| 31ce7fc48e | |||
| 99957861dc | |||
| 19d27b4ff6 | |||
| 7f2025ef6f | |||
| 3afe78f9e3 | |||
| eb763ed49c | |||
| 6537d79b19 | |||
| e55a2f42fe | |||
| 82d68e91b8 | |||
| 767eb5688c | |||
| 37fa05402e | |||
| 615281ae9a | |||
| 42532b1d44 | |||
| 1d4164711e | |||
| a50778380e | |||
| 159bce1ff2 | |||
| 22bc1e29a3 | |||
| 4ce9064fbb | |||
| 75f7a75379 | |||
| 398d7a2074 | |||
| b699008fa3 | |||
| b1f04badd5 | |||
| f0b5e56e43 | |||
| c644f42ea9 | |||
| 941c5fdf92 | |||
| 03de7082ab | |||
| def22f26f1 | |||
| fd37622ad6 | |||
| 96e08fce4c | |||
| 0f8eda40ad | |||
| 3285ee65da | |||
| 47339bda36 | |||
| 33269f9726 | |||
| 5b5a8318a4 | |||
| 42b3a44364 | |||
| 20278f24b3 | |||
| ae49c9cdb8 | |||
| ea08da8d10 | |||
| 0aa6fc2aa3 | |||
| ab6189e855 | |||
| 1c244db6ea | |||
| 3394040a8c | |||
| bc439fd4d2 | |||
| 16cfa5fead | |||
| 044c32e783 | |||
| 0d35173aab | |||
| 255c67ff92 | |||
| 9dc85a1963 | |||
| 91c27b30bf | |||
| 3ed094ff55 | |||
| 050aef8b7a | |||
| 420515f5b6 | |||
| 5dcd27e8b8 | |||
| 0333862e3c | |||
| 081e1edd24 | |||
| c454307d56 | |||
| 359a89ba62 | |||
| 3b73091cfb | |||
| c8beab76f1 | |||
| 599eaa3712 | |||
| 1de38fdfdf | |||
| 4d1f3644b0 | |||
| 71b3f13284 | |||
| c64bc3fe6b | |||
| 016bddb5c4 | |||
| 98d85810f3 | |||
| 3fc1191f6e | |||
| 52793ac244 | |||
| f8a1ae841d | |||
| 9d424742d6 | |||
| a9b73a6536 | |||
| 95584eb407 | |||
| ce7e2bc75a | |||
| 4bedc5d926 | |||
| ea7f98f8bb | |||
| bbdce9b25a | |||
| 1d75153698 | |||
| c177133daf | |||
| dad915f2ec | |||
| 54e4006d0d | |||
| 9cb590bf7a | |||
| 70c41dab96 | |||
| 99ac0a83c6 | |||
| 30c45b4503 | |||
| 49f552bf68 | |||
| 6f875cbb94 | |||
| f9331deec1 | |||
| c29bb94c3d | |||
| 8d884eebda | |||
| 2f022919ff | |||
| 91eeb6f275 | |||
| dc34531c4f | |||
| 12a241de81 | |||
| ef2567e0b6 | |||
| bb410b3158 | |||
| 7bbc717786 | |||
| a1870e07b5 | |||
| 43c8dd3ad0 | |||
| e57e43188c | |||
| 672a350f31 | |||
| c01098b672 | |||
| 566cbbd31b | |||
| 2375c2a23a | |||
| 5451899e48 | |||
| 6dd11c6441 | |||
| 045dd23a76 | |||
| 90e832af61 | |||
| 3d8c706835 | |||
| a37f6209ff | |||
| fc88125fe4 | |||
| 0aa79c7d35 | |||
| d484c0e3b0 | |||
| 7a35d1f44a | |||
| 7bfd048051 | |||
| 1433b69abe | |||
| c49ec85b3b | |||
| bdac1d5bc9 | |||
| 8baf928a5b | |||
| 20b01eda68 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,3 +21,4 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
vendor/
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
def "git.pbiernat.dev/egommerce/api-entities/http"
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewBasketAPI(ua string, redis *redis.Client) *BasketAPI {
|
|
||||||
return &BasketAPI{NewHttpClient(ua, redis)}
|
|
||||||
}
|
|
||||||
|
|
||||||
type BasketAPI struct {
|
|
||||||
httpClient *HttpClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *BasketAPI) GetBasket(basketID string) (*def.GetBasketResponse, error) {
|
|
||||||
req := &def.GetBasketRequest{BasketID: basketID}
|
|
||||||
res := new(def.GetBasketResponse)
|
|
||||||
if err := a.httpClient.SendGet("basket-svc", "/api/v1/basket", req, res); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *BasketAPI) GetBasketItems(basketID string) ([]*def.GetBasketItemsResponse, error) {
|
|
||||||
url := fmt.Sprintf("/api/v1/basket/%s/items", basketID)
|
|
||||||
var res []*def.GetBasketItemsResponse
|
|
||||||
if err := a.httpClient.SendGet("basket-svc", url, nil, &res); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
95
api/http.go
95
api/http.go
@@ -1,95 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HttpClient struct {
|
|
||||||
ua string
|
|
||||||
redis *redis.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHttpClient(ua string, redis *redis.Client) *HttpClient {
|
|
||||||
return &HttpClient{ua, redis}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HttpClient) SendGet(api, url string, data, out any) error {
|
|
||||||
res, err := c.sendRequest(api, url, http.MethodGet, data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := json.NewDecoder(res.Body)
|
|
||||||
err = decoder.Decode(&out)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
|
|
||||||
res, err := c.sendRequest(api, url, http.MethodPost, data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := json.NewDecoder(res.Body)
|
|
||||||
err = decoder.Decode(out)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Response, error) {
|
|
||||||
apiUrl := c.getApiUrl(api) + url
|
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
json, err := json.Marshal(&data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest(method, apiUrl, bytes.NewBuffer(json))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("User-Agent", c.ua)
|
|
||||||
res, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// defer res.Body.Close()
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HttpClient) getApiUrl(api string) string {
|
|
||||||
ctx, key, apiAddr := context.Background(), "internal__"+api+"__ips", api
|
|
||||||
// FIXME: key name ^^
|
|
||||||
cmd := c.redis.LLen(ctx, key)
|
|
||||||
if cmd.Err() == nil {
|
|
||||||
len := int(cmd.Val())
|
|
||||||
if len == 0 {
|
|
||||||
apiAddr = c.redis.LIndex(ctx, key, 0).Val()
|
|
||||||
} else {
|
|
||||||
apiAddr = c.redis.LIndex(ctx, key, int64(rand.Intn(len-0)+0)).Val()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if apiAddr == "" {
|
|
||||||
apiAddr = api // default api run on 80 int port
|
|
||||||
}
|
|
||||||
|
|
||||||
return "http://" + apiAddr
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
def "git.pbiernat.dev/egommerce/api-entities/http"
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewPricingAPI(ua string, redis *redis.Client) *PricingAPI {
|
|
||||||
return &PricingAPI{NewHttpClient(ua, redis)}
|
|
||||||
}
|
|
||||||
|
|
||||||
type PricingAPI struct {
|
|
||||||
httpClient *HttpClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *PricingAPI) GetProductPrice(productID int) (*def.ProductPriceResponse, error) {
|
|
||||||
url := fmt.Sprintf("/api/v1/product/%d", productID)
|
|
||||||
res := new(def.ProductPriceResponse)
|
|
||||||
if err := a.httpClient.SendGet("pricing-svc", url, nil, res); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
38
api/rest/basket.go
Normal file
38
api/rest/basket.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
basket "git.ego.freeddns.org/egommerce/api-entities/basket/dto"
|
||||||
|
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBasketAPI() *BasketAPI {
|
||||||
|
return &BasketAPI{NewHttpClient(cnf.GetEnv("API_REST_BASKET", "basket-svc"))}
|
||||||
|
}
|
||||||
|
|
||||||
|
type BasketAPI struct {
|
||||||
|
httpClient *HttpClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *BasketAPI) GetBasket(basketID string) (*basket.GetBasketResponseDTO, error) {
|
||||||
|
req := &basket.GetBasketRequestDTO{BasketID: basketID}
|
||||||
|
res := new(basket.GetBasketResponseDTO)
|
||||||
|
if err := a.httpClient.SendGet("/api/v1/basket", req, res); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *BasketAPI) GetBasketItems(basketID string) ([]*basket.GetBasketItemsResponseDTO, error) {
|
||||||
|
url := fmt.Sprintf("/api/v1/basket/items")
|
||||||
|
req := basket.GetBasketItemsRequestDTO{BasketID: basketID}
|
||||||
|
var res []*basket.GetBasketItemsResponseDTO
|
||||||
|
|
||||||
|
if err := a.httpClient.SendGet(url, req, &res); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
83
api/rest/http.go
Normal file
83
api/rest/http.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HttpClient struct {
|
||||||
|
baseURL string
|
||||||
|
userAgent string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHttpClient(baseURL string) *HttpClient {
|
||||||
|
return &HttpClient{baseURL: baseURL, userAgent: "internal-http-client"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HttpClient) SendGet(url string, data, out any) error {
|
||||||
|
fmt.Printf("Sending req to: %s%s\n", c.baseURL, url)
|
||||||
|
res, err := c.sendRequest(url, http.MethodGet, data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(res.Body)
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
err = decoder.Decode(&out)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HttpClient) SendPost(url string, data, out any) (any, error) {
|
||||||
|
res, err := c.sendRequest(url, http.MethodPost, data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(res.Body)
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
err = decoder.Decode(out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HttpClient) sendRequest(url, method string, data any) (*http.Response, error) {
|
||||||
|
apiUrl := c.baseURL + url
|
||||||
|
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // FIXME dev mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an HTTP client with the custom transport
|
||||||
|
client := &http.Client{Transport: tr} // FIXME dev mode
|
||||||
|
|
||||||
|
json, err := json.Marshal(&data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest(method, apiUrl, bytes.NewBuffer(json))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("User-Agent", c.userAgent)
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
25
api/rest/identity.go
Normal file
25
api/rest/identity.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
identity "git.ego.freeddns.org/egommerce/api-entities/identity/dto"
|
||||||
|
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IdentityAPI struct {
|
||||||
|
httpClient *HttpClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIdentityAPI() *IdentityAPI {
|
||||||
|
return &IdentityAPI{NewHttpClient(cnf.GetEnv("API_REST_IDENTITY", "identity-svc"))}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *IdentityAPI) CheckAccess(url, srv string) (*identity.CheckAccessResponseDTO, error) {
|
||||||
|
req := &identity.CheckAccessRequestDTO{URL: url, Service: srv}
|
||||||
|
res := new(identity.CheckAccessResponseDTO)
|
||||||
|
|
||||||
|
if err := a.httpClient.SendGet("/v1/access", req, res); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
26
api/rest/pricing.go
Normal file
26
api/rest/pricing.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
pricing "git.ego.freeddns.org/egommerce/api-entities/pricing/dto"
|
||||||
|
cnf "git.ego.freeddns.org/egommerce/go-api-pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewPricingAPI() *PricingAPI {
|
||||||
|
return &PricingAPI{NewHttpClient(cnf.GetEnv("API_REST_PRICING", "pricing-svc"))}
|
||||||
|
}
|
||||||
|
|
||||||
|
type PricingAPI struct {
|
||||||
|
httpClient *HttpClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *PricingAPI) GetProductPrice(productID int) (*pricing.ProductPriceResponseDTO, error) {
|
||||||
|
url := fmt.Sprintf("/api/v1/product/%d", productID)
|
||||||
|
res := new(pricing.ProductPriceResponseDTO)
|
||||||
|
if err := a.httpClient.SendGet(url, nil, res); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
28
client/postgresql/postgres.go
Normal file
28
client/postgresql/postgres.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package postgresql
|
||||||
|
|
||||||
|
// Jackc/pgx helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsDuplicatedRow(err error) error {
|
||||||
|
var pgErr *pgconn.PgError
|
||||||
|
|
||||||
|
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
|
||||||
|
return errors.New("duplicated row found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NoRowsInQuerySet(err error) error {
|
||||||
|
if err == pgx.ErrNoRows {
|
||||||
|
return errors.New("no rows found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
22
config/env.go
Normal file
22
config/env.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrLoadingEnvs error
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ErrLoadingEnvs = godotenv.Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetEnv(name string, defVal string) string {
|
||||||
|
env := os.Getenv(name)
|
||||||
|
if env == "" {
|
||||||
|
return defVal
|
||||||
|
}
|
||||||
|
|
||||||
|
return env
|
||||||
|
}
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
package consul
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
consul "github.com/hashicorp/consul/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
Name string
|
|
||||||
Address string
|
|
||||||
appID string
|
|
||||||
domain string
|
|
||||||
pathPrefix string
|
|
||||||
port int
|
|
||||||
ttl time.Duration
|
|
||||||
agent *consul.Agent
|
|
||||||
kv *consul.KV
|
|
||||||
catalog *consul.Catalog
|
|
||||||
}
|
|
||||||
|
|
||||||
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
|
||||||
|
|
||||||
func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort int) (*Service, error) {
|
|
||||||
s := new(Service)
|
|
||||||
s.Name = name
|
|
||||||
s.Address = hostname
|
|
||||||
s.appID = id
|
|
||||||
s.domain = domain
|
|
||||||
s.pathPrefix = pathPrefix
|
|
||||||
s.port = appPort
|
|
||||||
s.ttl = time.Second * 15
|
|
||||||
|
|
||||||
client, err := consul.NewClient(newClientConfig(servAddr))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s.agent = client.Agent()
|
|
||||||
s.kv = client.KV()
|
|
||||||
s.catalog = client.Catalog()
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newClientConfig(serverAddr string) *consul.Config {
|
|
||||||
conf := consul.DefaultConfig()
|
|
||||||
conf.Address = serverAddr
|
|
||||||
|
|
||||||
return conf
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) GetID() string {
|
|
||||||
return fmt.Sprintf("%s_%s", s.Name, s.appID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) GetFullAddr() string {
|
|
||||||
return fmt.Sprintf("http://%s:%d/", s.Address, s.port)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Register() error {
|
|
||||||
def := &consul.AgentServiceRegistration{
|
|
||||||
ID: s.GetID(),
|
|
||||||
Name: s.Name,
|
|
||||||
Address: s.Address,
|
|
||||||
Port: s.port,
|
|
||||||
Tags: s.getTags(),
|
|
||||||
Check: &consul.AgentServiceCheck{
|
|
||||||
TTL: s.ttl.String(),
|
|
||||||
DeregisterCriticalServiceAfter: "5s",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.agent.ServiceRegister(def); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go func(s *Service) { // startup register
|
|
||||||
ticker := time.NewTicker(time.Millisecond * 100)
|
|
||||||
for range ticker.C {
|
|
||||||
if ok, _ := s.healthCheck(); ok {
|
|
||||||
ticker.Stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(s)
|
|
||||||
|
|
||||||
go func(s *Service) { // TTL
|
|
||||||
interval := s.ttl - time.Second*2 // 2 seconds overhead
|
|
||||||
ticker := time.NewTicker(interval)
|
|
||||||
for range ticker.C {
|
|
||||||
if _, err := s.healthCheck(); err != nil {
|
|
||||||
fmt.Printf("TTL Error: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(s)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (s *Service) Unregister() error {
|
|
||||||
return s.agent.ServiceDeregister(s.GetID())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) KV() *consul.KV {
|
|
||||||
return s.kv
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Catalog() *consul.Catalog {
|
|
||||||
return s.catalog
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) healthCheck() (bool, error) {
|
|
||||||
alive := func() bool {
|
|
||||||
client := &http.Client{}
|
|
||||||
healthUrl := s.GetFullAddr() + "health"
|
|
||||||
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
req.Header.Set("User-Agent", "Health Check")
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
return resp.StatusCode == http.StatusOK
|
|
||||||
}()
|
|
||||||
|
|
||||||
if alive {
|
|
||||||
if err := s.agent.PassTTL("service:"+s.GetID(), "OK"); err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.agent.FailTTL("service:"+s.GetID(), ErrServiceUnavailable.Error()); err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return false, ErrServiceUnavailable
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) getTags() []string {
|
|
||||||
tags := []string{
|
|
||||||
"traefik.enable=true",
|
|
||||||
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
|
|
||||||
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
|
||||||
"traefik.http.routers." + s.Name + ".tls=true",
|
|
||||||
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
|
||||||
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",requestid_" + s.Name + ",stripprefix_" + s.Name,
|
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
|
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
|
|
||||||
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL",
|
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authRequestHeaders=Cookie",
|
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authResponseHeaders=Set-Cookie, Server",
|
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
|
|
||||||
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
|
|
||||||
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
|
|
||||||
"traefik.tls.certificates.certfile=/certs/client.cert",
|
|
||||||
"traefik.tls.certificates.keyfile=/certs/client.key",
|
|
||||||
}
|
|
||||||
|
|
||||||
return tags
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package fluentd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ParseAddr(addr string) (string, int, error) {
|
|
||||||
p := strings.Split(addr, ":")
|
|
||||||
fHost := p[0]
|
|
||||||
fPort, err := strconv.Atoi(p[1])
|
|
||||||
if err != nil {
|
|
||||||
return "", 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return fHost, fPort, nil
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package fluentd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/fluent/fluent-logger-golang/fluent"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Logger struct {
|
|
||||||
fluent *fluent.Fluent
|
|
||||||
appName string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLogger(appName, fHost string, fPort int) (*Logger, error) {
|
|
||||||
config := fluent.Config{
|
|
||||||
FluentHost: fHost,
|
|
||||||
FluentPort: fPort,
|
|
||||||
// WriteTimeout: -1,
|
|
||||||
}
|
|
||||||
fluent, err := fluent.New(config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Logger{fluent, appName}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) Log(format string, v ...any) {
|
|
||||||
mapData := map[string]string{
|
|
||||||
"message": fmt.Sprintf(format, v...),
|
|
||||||
}
|
|
||||||
err := l.fluent.Post(l.appName, mapData)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error sending log: ", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) Close() error {
|
|
||||||
return l.fluent.Close()
|
|
||||||
}
|
|
||||||
37
go.mod
37
go.mod
@@ -1,31 +1,20 @@
|
|||||||
module git.pbiernat.dev/egommerce/go-api-pkg
|
module git.ego.freeddns.org/egommerce/go-api-pkg
|
||||||
|
|
||||||
go 1.18
|
go 1.24
|
||||||
|
|
||||||
|
require github.com/joho/godotenv v1.5.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fluent/fluent-logger-golang v1.9.0
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/hashicorp/consul/api v1.18.0
|
|
||||||
github.com/streadway/amqp v1.0.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
|
git.ego.freeddns.org/egommerce/api-entities v0.3.50
|
||||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/jackc/pgx/v5 v5.7.6
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/fatih/color v1.9.0 // indirect
|
github.com/stretchr/testify v1.8.3 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
|
golang.org/x/crypto v0.37.0 // indirect
|
||||||
github.com/hashicorp/go-hclog v0.12.0 // indirect
|
golang.org/x/text v0.24.0 // indirect
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
|
||||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
|
||||||
github.com/hashicorp/serf v0.10.1 // indirect
|
|
||||||
github.com/mattn/go-colorable v0.1.6 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
|
||||||
github.com/philhofer/fwd v1.1.1 // indirect
|
|
||||||
github.com/tinylib/msgp v1.1.6 // indirect
|
|
||||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
201
go.sum
201
go.sum
@@ -1,180 +1,33 @@
|
|||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
git.ego.freeddns.org/egommerce/api-entities v0.3.50 h1:3BYB+0gGSkXf4JlcYQtlLhe3goL5aL8A9M54LlzdlfM=
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
|
git.ego.freeddns.org/egommerce/api-entities v0.3.50/go.mod h1:D58YWJz0jvARi/7pNpDMzp00nfk9YLOj9zjcKRDHBhY=
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
|
||||||
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
|
||||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
|
|
||||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
|
||||||
github.com/fluent/fluent-logger-golang v1.9.0 h1:zUdY44CHX2oIUc7VTNZc+4m+ORuO/mldQDA7czhWXEg=
|
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||||
github.com/fluent/fluent-logger-golang v1.9.0/go.mod h1:2/HCT/jTy78yGyeNGQLGQsjF3zzzAuy6Xlk6FCMV5eU=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
|
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
|
||||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
|
||||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
|
||||||
github.com/hashicorp/consul/api v1.18.0 h1:R7PPNzTCeN6VuQNDwwhZWJvzCtGSrNpJqfb22h3yH9g=
|
|
||||||
github.com/hashicorp/consul/api v1.18.0/go.mod h1:owRRGJ9M5xReDC5nfT8FTJrNAPbT4NM6p/k+d03q2v4=
|
|
||||||
github.com/hashicorp/consul/sdk v0.13.0 h1:lce3nFlpv8humJL8rNrrGHYSKc3q+Kxfeg3Ii1m6ZWU=
|
|
||||||
github.com/hashicorp/consul/sdk v0.13.0/go.mod h1:0hs/l5fOVhJy/VdcoaNqUSi2AUs95eF5WKtv+EYIQqE=
|
|
||||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
|
||||||
github.com/hashicorp/go-hclog v0.12.0 h1:d4QkX8FRTYaKaCZBoXYY8zJX2BXjWxurN/GA2tkrmZM=
|
|
||||||
github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
|
||||||
github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4=
|
|
||||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
|
||||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
|
||||||
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
|
|
||||||
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
|
|
||||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
|
||||||
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
|
|
||||||
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
|
|
||||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
|
|
||||||
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
|
||||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
|
||||||
github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc=
|
|
||||||
github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR/prTM=
|
|
||||||
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
|
|
||||||
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
|
|
||||||
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
|
|
||||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
|
||||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
|
||||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
|
||||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
|
||||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
|
||||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
|
||||||
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
|
|
||||||
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
|
|
||||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
|
||||||
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
|
|
||||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
|
||||||
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
|
||||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
|
||||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs=
|
|
||||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
|
||||||
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
|
|
||||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
|
||||||
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
|
||||||
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
|
|
||||||
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
|
||||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
|
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
|
||||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
|
|
||||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
|
|
||||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package rabbitmq
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/streadway/amqp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Open(url string) (*amqp.Connection, *amqp.Channel, error) {
|
|
||||||
conn, err := amqp.Dial(url)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ch, err := conn.Channel()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to open a channel: %v\n", err)
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn, ch, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Close(conn *amqp.Connection) error {
|
|
||||||
return conn.Close()
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package rabbitmq
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/streadway/amqp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Message map[string]interface{}
|
|
||||||
|
|
||||||
func Serialize(msg any) (string, error) {
|
|
||||||
var b bytes.Buffer
|
|
||||||
encoder := json.NewEncoder(&b)
|
|
||||||
err := encoder.Encode(msg)
|
|
||||||
|
|
||||||
return b.String(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Deserialize(b []byte) (Message, error) {
|
|
||||||
var msg Message
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
decoder := json.NewDecoder(buf)
|
|
||||||
err := decoder.Decode(&msg)
|
|
||||||
|
|
||||||
return msg, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewExchange(chn *amqp.Channel, name string) error {
|
|
||||||
err := chn.ExchangeDeclare(
|
|
||||||
name,
|
|
||||||
"direct", // type
|
|
||||||
true, // durable
|
|
||||||
false, // auto-deleted
|
|
||||||
false, // internal
|
|
||||||
false, // no-wait
|
|
||||||
nil, // arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Publish(chn *amqp.Channel, name, routingKey string, msg any) error {
|
|
||||||
jsonData, err := Serialize(msg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msgBody := fmt.Sprintf(`{"event":"%T","data":%s}`, msg, jsonData)
|
|
||||||
chn.Publish(
|
|
||||||
name, // exchange name
|
|
||||||
routingKey, // routing key
|
|
||||||
false, // mandatory
|
|
||||||
false, // immediate
|
|
||||||
amqp.Publishing{
|
|
||||||
ContentType: "application/json",
|
|
||||||
Body: []byte(msgBody),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func BindQueueToExchange(chn *amqp.Channel, queueName, exchName, routingKey string) error {
|
|
||||||
err := chn.QueueBind(
|
|
||||||
queueName, // queue name
|
|
||||||
routingKey, // routing key
|
|
||||||
exchName, // exchange name
|
|
||||||
false,
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to bind a queue: %s\n", queueName)
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user