refactor:
This commit is contained in:
parent
81e75e5a9c
commit
d62ae666d5
57 changed files with 656 additions and 310 deletions
1
pkg/external/aws/aws.go
vendored
Normal file
1
pkg/external/aws/aws.go
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
package aws
|
1
pkg/external/kafka/kafka.go
vendored
Normal file
1
pkg/external/kafka/kafka.go
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
package kafka
|
1
pkg/external/ms-auth/client.go
vendored
Normal file
1
pkg/external/ms-auth/client.go
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
package ms_auth
|
71
pkg/external/pandoc/pandoc.go
vendored
Normal file
71
pkg/external/pandoc/pandoc.go
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
package pandoc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
address string
|
||||
}
|
||||
|
||||
type PandocClient interface {
|
||||
ConvertLatexToHtml5(ctx context.Context, text string) (string, error)
|
||||
}
|
||||
|
||||
func NewPandocClient(client *http.Client, address string) *Client {
|
||||
return &Client{
|
||||
client: client,
|
||||
address: address,
|
||||
}
|
||||
}
|
||||
|
||||
type convertRequest struct {
|
||||
Text string `json:"text"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
}
|
||||
|
||||
func (client *Client) convert(ctx context.Context, text, from, to string) (string, error) {
|
||||
body, err := json.Marshal(convertRequest{
|
||||
Text: text,
|
||||
From: from,
|
||||
To: to,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(body)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, client.address, buf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := client.client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", err
|
||||
}
|
||||
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func (client *Client) ConvertLatexToHtml5(ctx context.Context, text string) (string, error) {
|
||||
return client.convert(ctx, text, "latex", "html5")
|
||||
}
|
30
pkg/external/postgres/postgres.go
vendored
Normal file
30
pkg/external/postgres/postgres.go
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
maxOpenConns = 60
|
||||
connMaxLifetime = 120
|
||||
maxIdleConns = 30
|
||||
connMaxIdleTime = 20
|
||||
)
|
||||
|
||||
func NewPostgresDB(dsn string) (*sqlx.DB, error) {
|
||||
db, err := sqlx.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db.SetMaxOpenConns(maxOpenConns)
|
||||
db.SetConnMaxLifetime(connMaxLifetime * time.Second)
|
||||
db.SetMaxIdleConns(maxIdleConns)
|
||||
db.SetConnMaxIdleTime(connMaxIdleTime * time.Second)
|
||||
if err = db.Ping(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
12
pkg/external/valkey/valkey.go
vendored
Normal file
12
pkg/external/valkey/valkey.go
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
package valkey
|
||||
|
||||
import "github.com/valkey-io/valkey-go"
|
||||
|
||||
func NewValkeyClient(dsn string) (valkey.Client, error) {
|
||||
opts, err := valkey.ParseURL(dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return valkey.NewClient(opts)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue