feat: remove v1

This commit is contained in:
Rogee
2024-12-04 14:11:50 +08:00
parent 0803c2f54f
commit cdf8acf78f
63 changed files with 314 additions and 2461 deletions

View File

@@ -0,0 +1,33 @@
package testx
import (
"os"
"testing"
"backend/providers/hashids"
"git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container"
"github.com/rogeecn/fabfile"
. "github.com/smartystreets/goconvey/convey"
)
func Default(providers ...container.ProviderContainer) container.Providers {
return append(container.Providers{
hashids.DefaultProvider(),
}, providers...)
}
func Serve(providers container.Providers, t *testing.T, invoke any) {
Convey("tests boot up", t, func() {
file := fabfile.MustFind("config.toml")
localEnv := os.Getenv("ENV_LOCAL")
if localEnv != "" {
file = fabfile.MustFind("config." + localEnv + ".toml")
}
So(atom.LoadProviders(file, providers), ShouldBeNil)
So(container.Container.Invoke(invoke), ShouldBeNil)
})
}

View File

@@ -22,3 +22,7 @@ AppId = "wx45745a8c51091ae0"
AppSecret = "2ab33bc79d9b47efa4abef19d66e1977"
Token = "W8Xhw5TivYBgY"
AesKey = "F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI"
[HashIDs]
Salt = "LiXi.Y@140202"

View File

@@ -4,6 +4,7 @@ go 1.22.0
require (
git.ipao.vip/rogeecn/atom v1.0.10
github.com/etherlabsio/go-m3u8 v1.0.0
github.com/go-jet/jet/v2 v2.12.0
github.com/gofiber/fiber/v3 v3.0.0-beta.3
github.com/gofrs/uuid v4.4.0+incompatible
@@ -14,6 +15,7 @@ require (
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/pressly/goose/v3 v3.23.0
github.com/rogeecn/fabfile v1.4.0
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/smartystreets/goconvey v1.6.4
@@ -21,6 +23,7 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.9.0
go.uber.org/dig v1.18.0
golang.org/x/net v0.31.0
golang.org/x/sync v0.9.0
@@ -70,7 +73,6 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect

View File

@@ -38,6 +38,7 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.ipao.vip/rogeecn/atom v1.0.10 h1:U/10G17rkULOAhgqGUD6rhcdJ5vJNxGv5gelAZTcJeU=
git.ipao.vip/rogeecn/atom v1.0.10/go.mod h1:YY1nlkYnMpZxen5R64mblMWm+LJYyvWiw3P8P2eO7dY=
github.com/AlekSi/pointer v1.0.0/go.mod h1:1kjywbfcPFCmncIxtk6fIEub6LKrfMz3gc5QKVOSOA8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
@@ -70,6 +71,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etherlabsio/go-m3u8 v1.0.0 h1:d3HJVr8wlbvJO20ksKEyvDYf4bcM7v8YV3W83fHswL0=
github.com/etherlabsio/go-m3u8 v1.0.0/go.mod h1:RzDiaXgaYnIEzZUmVUD/xMRFR7bY7U5JaCnp8XYLmXU=
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
@@ -301,6 +304,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogeecn/atom v1.0.8 h1:Dr/pF3my7ZxB0OR5IN5Xw4ztjDsL+KpOHq31yxidb8w=
github.com/rogeecn/atom v1.0.8/go.mod h1:BgKU29c4pVZFgumyvIr5rGTG1qEbIOrAQbAsd73cFSA=
github.com/rogeecn/fabfile v1.4.0 h1:Rw7/7OH8cV4aRPw79Oa4hHHFKaC/ol+sNmGcB/usHaQ=
github.com/rogeecn/fabfile v1.4.0/go.mod h1:EPwX7TtVcIWSLJkJAqxSzYjM/aV1Q0wymcaXqnMgzas=
github.com/rogpeppe/clock v0.0.0-20190514195947-2896927a307a h1:3QH7VyOaaiUHNrA9Se4YQIRkDTCw1EJls9xTUCaCeRM=
github.com/rogpeppe/clock v0.0.0-20190514195947-2896927a307a/go.mod h1:4r5QyqhjIWCcK8DO4KMclc5Iknq5qVBAlbYYzAbUScQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

View File

@@ -1,9 +1,8 @@
package medias
import (
"database/sql"
"backend/providers/http"
"database/sql"
"git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container"

View File

@@ -1,6 +1,8 @@
package middlewares
import (
"backend/modules/users"
"backend/providers/jwt"
"backend/providers/wechat"
"git.ipao.vip/rogeecn/atom/container"
@@ -10,9 +12,13 @@ import (
func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func(
client *wechat.Client,
jwt *jwt.JWT,
userSvc *users.Service,
) (*Middlewares, error) {
obj := &Middlewares{
client: client,
client: client,
jwt: jwt,
userSvc: userSvc,
}
if err := obj.Prepare(); err != nil {
return nil, err

View File

@@ -0,0 +1,140 @@
package tasks
import (
"os"
"os/exec"
"path/filepath"
"strings"
"backend/modules/medias"
"github.com/etherlabsio/go-m3u8/m3u8"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
hashids "github.com/speps/go-hashids/v2"
)
// @provider
type DiscoverMedias struct {
hashId *hashids.HashID
mediasSvc *medias.Service
log *logrus.Entry `inject:"false"`
}
func (d *DiscoverMedias) Prepare() error {
d.log = log.WithField("module", "DiscoverMedias")
return nil
}
func (d *DiscoverMedias) getHashID(ids ...int64) (string, error) {
return d.hashId.EncodeInt64(ids)
}
func (d *DiscoverMedias) getSubDirs(root string) ([]string, error) {
fd, err := os.Open(root)
if err != nil {
return nil, errors.Wrapf(err, "open root directory: %s", root)
}
defer fd.Close()
entries, err := fd.Readdir(-1)
if err != nil {
return nil, errors.Wrapf(err, "read root directory: %s", root)
}
var paths []string
for _, entry := range entries {
if entry.IsDir() {
paths = append(paths, entry.Name())
}
}
return paths, nil
}
func (d *DiscoverMedias) globVideo(root string) []string {
files := []string{}
exts := []string{"*.mp4", "*.MP4", "*.mov", "*.MOV"}
for _, ext := range exts {
fs, _ := filepath.Glob(filepath.Join(root, ext))
files = append(files, fs...)
}
return files
}
func (d *DiscoverMedias) globAudio(root string) []string {
files := []string{}
exts := []string{"*.mp3", "*.MP3", "*.wav", "*.WAV"}
for _, ext := range exts {
fs, _ := filepath.Glob(filepath.Join(root, ext))
files = append(files, fs...)
}
return files
}
// ensureDirectory ensure the directory exists
func (d *DiscoverMedias) ensureDirectory(dir string) error {
st, err := os.Stat(dir)
if os.IsNotExist(err) {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return errors.Wrapf(err, "mkdir: %s", dir)
}
return nil
}
if !st.IsDir() {
os.RemoveAll(dir)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return errors.Wrapf(err, "mkdir: %s", dir)
}
}
return nil
}
func (d *DiscoverMedias) ffmpegVideoToM3U8(input string, output string) error {
output = filepath.Join(output, "video")
if err := d.ensureDirectory(output); err != nil {
return errors.Wrapf(err, "ensure directory: %s", output)
}
args := []string{
"-i", input,
"-c:v", "libx264",
"-c:a", "aac",
"-strict",
"-2",
"-f", "hls",
"-hls_time", "10",
"-hls_list_size", "0",
"-hls_segment_filename", filepath.Join(output, "%d.ts"),
filepath.Join(output, "index.m3u8"),
}
log.Infof("cmd: ffmpeg %s", strings.Join(args, " "))
logs, err := exec.Command("ffmpeg", args...).Output()
if err != nil {
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", input)
}
d.log.Infof("ffmpeg video to m3u8: %s", logs)
return nil
}
// parseM3u8File parse the m3u8 file
func (d *DiscoverMedias) parseM3u8File(file string) (*m3u8.Playlist, error) {
platList, err := m3u8.ReadFile(file)
if err != nil {
return nil, errors.Wrapf(err, "read m3u8 file:%s", file)
}
return platList, nil
}

View File

@@ -0,0 +1,84 @@
package tasks
import (
"os"
"testing"
"backend/common/service/testx"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/suite"
"go.uber.org/dig"
)
type DiscoverMediasInjectParams struct {
dig.In
Svc *DiscoverMedias
}
type DiscoverMediasTestSuite struct {
suite.Suite
DiscoverMediasInjectParams
}
func Test_DiscoverMedias(t *testing.T) {
providers := testx.Default().With(
Provide,
)
testx.Serve(providers, t, func(params DiscoverMediasInjectParams) {
suite.Run(t, &DiscoverMediasTestSuite{DiscoverMediasInjectParams: params})
})
}
func (t *DiscoverMediasTestSuite) Test_getHashID() {
Convey("TestDiscoverMedias_getHashID", t.T(), func() {
hashId, err := t.Svc.getHashID(10, 11, 12)
So(err, ShouldBeNil)
t.T().Logf("HashID: %s", hashId)
})
}
func (t *DiscoverMediasTestSuite) Test_getSubDirs() {
Convey("Test_getSubDirs", t.T(), func() {
dirs, err := t.Svc.getSubDirs("/mnt/yangpingliang/动态曲谱")
So(err, ShouldBeNil)
t.T().Logf("Dirs: %+v", dirs)
})
}
func (t *DiscoverMediasTestSuite) Test_getVideo() {
Convey("Test_getVideo", t.T(), func() {
dirs := t.Svc.globVideo("/mnt/yangpingliang/动态曲谱/河北梆子伴奏《李慧娘》依然还我生前摸样")
t.T().Logf("Dirs: %+v", dirs)
})
}
func (t *DiscoverMediasTestSuite) Test_getAudio() {
Convey("Test_getAudio", t.T(), func() {
dirs := t.Svc.globAudio("/mnt/yangpingliang/动态曲谱/河北梆子伴奏《李慧娘》依然还我生前摸样")
t.T().Logf("Dirs: %+v", dirs)
})
}
func (t *DiscoverMediasTestSuite) Test_ffmpegVideoToM3U8() {
Convey("Test_ffmpegVideoToM3U8", t.T(), func() {
output := "/projects/mp-qvyun/backend/fixtures/medias/abc"
os.RemoveAll(output)
err := t.Svc.ffmpegVideoToM3U8("/projects/mp-qvyun/backend/fixtures/medias/video.mp4", output)
So(err, ShouldBeNil)
})
}
func (t *DiscoverMediasTestSuite) Test_parseM3u8File() {
Convey("TestDiscoverMedias_parseM3u8File", t.T(), func() {
file := "/projects/mp-qvyun/backend/fixtures/medias/abc/video/index.m3u8"
playlist, err := t.Svc.parseM3u8File(file)
So(err, ShouldBeNil)
t.T().Logf("ListType: %+v", playlist)
})
}

View File

@@ -0,0 +1,22 @@
package tasks
import (
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/utils/opt"
hashids "github.com/speps/go-hashids/v2"
)
func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func(
hashId *hashids.HashID,
) (*DiscoverMedias, error) {
obj := &DiscoverMedias{
hashId: hashId,
}
return obj, nil
}); err != nil {
return err
}
return nil
}

View File

@@ -17,7 +17,7 @@ func Provide(opts ...opt.Option) error {
data := hashids.NewData()
data.MinLength = int(config.MinLength)
if data.MinLength == 0 {
data.MinLength = 5
data.MinLength = 10
}
data.Salt = config.Salt
@@ -25,8 +25,9 @@ func Provide(opts ...opt.Option) error {
data.Salt = "default-salt-key"
}
if config.Alphabet != "" {
data.Alphabet = config.Alphabet
data.Alphabet = config.Alphabet
if config.Alphabet == "" {
data.Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
}
return hashids.NewWithData(data)

View File

@@ -1,3 +1,13 @@
https://github.com/etherlabsio/go-m3u8
https://github.com/FlashFeiFei/m3u8Transmit/blob/main/main.go
https://github.com/FlashFeiFei/m3u8Transmit/blob/main/main.go
### mp4 -> ts
ffmpeg -y -i video.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb video.ts
### ts -> m3u8
ffmpeg -y -i video.ts -hls_time 10 -hls_segment_filename ./m3u8/s%d.ts ./m3u8/index.m3u8
### mp4 to m3u8
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict -2 -f hls output.m3u8

View File

View File

@@ -1,6 +0,0 @@
.PHONY: model
model:
rm -rf ./database/models/qvyun
jet -dsn=postgresql://postgres:xixi0202@10.1.1.3:5432/qvyun?sslmode=disable -path=./database/models
gofumpt -w -l -extra ./database

View File

@@ -1,40 +0,0 @@
package cmd
import (
"context"
"git.ipao.vip/rogeecn/mp-qvyun/conf"
"git.ipao.vip/rogeecn/mp-qvyun/database"
"github.com/gofiber/fiber/v3/log"
"github.com/pkg/errors"
"github.com/pressly/goose/v3"
"github.com/spf13/cobra"
)
func CommandMigrate(root *cobra.Command) {
cmd := &cobra.Command{
Use: "migrate",
Short: "migrate",
RunE: commandMigrate,
}
root.AddCommand(cmd)
}
func commandMigrate(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
args = append(args, "up")
}
db, err := database.GetDB(conf.C.Database)
if err != nil {
return errors.Wrap(err, "get db")
}
action, args := args[0], args[1:]
log.Infof("migration action: %s args: %+v", action, args)
goose.SetBaseFS(database.MigrationFS)
goose.SetTableName("migrations")
return goose.RunContext(context.Background(), action, db, "migrations", args...)
}

View File

@@ -1,61 +0,0 @@
package cmd
import (
"fmt"
"git.ipao.vip/rogeecn/mp-qvyun/conf"
"git.ipao.vip/rogeecn/mp-qvyun/pkg/middlewares/fiberv3"
"git.ipao.vip/rogeecn/mp-qvyun/pkg/wechat"
"github.com/gofiber/fiber/v3"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func CommandServe(root *cobra.Command) {
cmd := &cobra.Command{
Use: "serve",
Short: "start http server",
RunE: commandServe,
}
root.AddCommand(cmd)
}
func commandServe(cmd *cobra.Command, args []string) error {
wechatClient := wechat.New(
wechat.WithAppID(conf.C.Wechat.AppID),
wechat.WithAppSecret(conf.C.Wechat.AppSecret),
wechat.WithAESKey(conf.C.Wechat.AesKey),
wechat.WithToken(conf.C.Wechat.Token),
)
wechatMiddlewares := fiberv3.Init(wechatClient)
// create a new fiber server
app := fiber.New()
app.Use(LogAll)
app.Use(wechatMiddlewares.Verify)
app.Use(wechatMiddlewares.AuthUserInfo)
app.Use(wechatMiddlewares.SilentAuth)
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("Hello World")
})
// listen on port 3000
if err := app.Listen(fmt.Sprintf(":%d", conf.C.Port)); err != nil {
return errors.Wrap(err, "http server listen")
}
return nil
}
func LogAll(c fiber.Ctx) error {
log.Info("------------------------------------------")
log.Infof("Request Method: %s", c.Method())
log.Infof("Request Headers: %s", &c.Request().Header)
log.Infof("Request URL: %s", c.OriginalURL())
log.Infof("Request Query: %+v", c.Queries())
log.Infof("Request Body: %s", c.BodyRaw())
log.Info("------------------------------------------")
return c.Next()
}

View File

@@ -1,82 +0,0 @@
package conf
import (
"fmt"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
var C *Config
// WechatAppID = "wx45745a8c51091ae0"
// WechatAppSecret = "2ab33bc79d9b47efa4abef19d66e1977"
// WechatToken = "W8Xhw5TivYBgY"
// WechatAesKey = "F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI"
type Config struct {
Debug bool `mapstructure:"debug"`
Port uint `mapstructure:"port"`
Database Database `mapstructure:"database"`
Wechat Wechat `mapstructure:"wechat"`
}
type Database struct {
Database string `mapstructure:"database"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Host string `mapstructure:"host"`
Port uint `mapstructure:"port"`
SslMode string `mapstructure:"ssl_mode"`
TimeZone string `mapstructure:"time_zone"`
}
func (m Database) DSN() string {
tpl := "host=%s port=%d user=%s password=%s dbname=%s sslmode=%s TimeZone=%s"
if m.Username == "" {
m.Username = "postgres"
}
if m.Port == 0 {
m.Port = 5432
}
if m.SslMode == "" {
m.SslMode = "disable"
}
if m.TimeZone == "" {
m.TimeZone = "Asia/Shanghai"
}
return fmt.Sprintf(tpl, m.Host, m.Port, m.Username, m.Password, m.Database, m.SslMode, m.TimeZone)
}
type Wechat struct {
AppID string `mapstructure:"app_id"`
AppSecret string `mapstructure:"app_secret"`
Token string `mapstructure:"token"`
AesKey string `mapstructure:"aes_key"`
}
func Load(file string) error {
viper.SetConfigType("yaml")
if file != "" {
viper.SetConfigFile(file)
} else {
viper.SetConfigName("config")
viper.AddConfigPath(".")
}
log.Infof("load config file")
if err := viper.ReadInConfig(); err != nil {
return errors.Wrap(err, "read config file")
}
log.Infof("use config file: %s", viper.ConfigFileUsed())
if err := viper.Unmarshal(&C); err != nil {
return errors.Wrap(err, "unmarshal config")
}
return nil
}

View File

@@ -1,6 +0,0 @@
port: 8000
wechat:
app_id: wxf5bf0adeb99c2afd
app_secret: 3cf8fad4aa414f2b861399f111b22bb5
token: W8Xhw5TivYBgY
aes_key: F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI

View File

@@ -1,12 +0,0 @@
debug: true
port: 8000
database:
host: 10.1.1.3
database: qvyun
password: xixi0202
wechat:
app_id: wx45745a8c51091ae0
app_secret: 2ab33bc79d9b47efa4abef19d66e1977
token: W8Xhw5TivYBgY
aes_key: F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI

View File

@@ -1,15 +0,0 @@
package main
// const (
// WechatAppID = "wxf5bf0adeb99c2afd"
// WechatAppSecret = "3cf8fad4aa414f2b861399f111b22bb5"
// WechatToken = "W8Xhw5TivYBgY"
// WechatAesKey = "F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI"
// )
const (
WechatAppID = "wx45745a8c51091ae0"
WechatAppSecret = "2ab33bc79d9b47efa4abef19d66e1977"
WechatToken = "W8Xhw5TivYBgY"
WechatAesKey = "F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI"
)

View File

@@ -1,59 +0,0 @@
package database
import (
"database/sql"
"embed"
"sync"
"git.ipao.vip/rogeecn/mp-qvyun/conf"
"github.com/gofiber/fiber/v3/log"
_ "github.com/lib/pq"
"github.com/pkg/errors"
)
//go:embed migrations/*
var MigrationFS embed.FS
var (
mutex sync.Mutex
db *sql.DB
)
func Close() error {
if db == nil {
return nil
}
return db.Close()
}
func GetDB(config conf.Database) (*sql.DB, error) {
mutex.Lock()
defer mutex.Unlock()
if db != nil {
return db, nil
}
once := sync.OnceValues(func() (*sql.DB, error) {
log.Debugf("connect postgres with dsn: '%s'", config.DSN())
db, err := sql.Open("postgres", config.DSN())
if err != nil {
return nil, errors.Wrap(err, "connect database")
}
if err := db.Ping(); err != nil {
db.Close()
return nil, errors.Wrap(err, "ping database")
}
return db, err
})
var err error
db, err = once()
if err != nil {
return nil, err
}
return db, err
}

View File

@@ -1,122 +0,0 @@
-- +goose Up
-- +goose StatementBegin
-- table users
CREATE TABLE
users (
id SERIAL8 PRIMARY KEY,
open_id VARCHAR(128) NOT NULL,
union_id VARCHAR(128),
oauth jsonb ,
expire_in timestamp NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL
);
CREATE INDEX idx_users_open_id ON users (open_id);
CREATE INDEX idx_users_union_id ON users (union_id);
-- table tenants
CREATE TABLE
tenants (
id SERIAL8 PRIMARY KEY,
name VARCHAR(128) NOT NULL,
slug VARCHAR(128) NOT NULL,
description VARCHAR(128),
expire_at timestamp NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL
);
-- table users_tenants
CREATE TABLE
users_tenants (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
created_at timestamp NOT NULL
);
CREATE INDEX idx_users_tenants_user_id ON users_tenants (user_id);
CREATE INDEX idx_users_tenants_tenant_id ON users_tenants (tenant_id);
CREATE TABLE tenant_user_balances (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
balance INT8 NOT NULL
);
CREATE INDEX idx_tenant_user_balance_user_id ON tenant_user_balances (user_id);
CREATE INDEX idx_tenant_user_balance_tenant_id ON tenant_user_balances (tenant_id);
-- table user_balance_history
CREATE TABLE user_balance_histories (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
balance INT8 NOT NULL,
target jsonb ,
type VARCHAR(128) NOT NULL, -- charge, consume, refund
created_at timestamp NOT NULL
);
CREATE INDEX idx_user_balance_histories_user_id ON user_balance_histories (user_id);
CREATE INDEX idx_user_balance_histories_tenant_id ON user_balance_histories (tenant_id);
-- medias
CREATE TABLE
medias (
id SERIAL8 PRIMARY KEY,
tenant_id INT8 NOT NULL,
title VARCHAR(198) NOT NULL,
description VARCHAR(198) NOT NULL,
price INT8 NOT NULL,
discount INT8 NOT NULL,
publish BOOL NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL
);
CREATE INDEX idx_medias_tenant_id ON medias (tenant_id);
CREATE INDEX idx_medias_title ON medias (title);
CREATE TABLE
media_resources (
id SERIAL8 PRIMARY KEY,
media_id INT8 NOT NULL,
type VARCHAR(128) NOT NULL,
source jsonb ,
size INT8 NOT NULL,
publish BOOL NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL
);
CREATE INDEX idx_media_resources_media_id ON media_resources (media_id);
CREATE TABLE user_medias (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
media_id INT8 NOT NULL,
price INT8 NOT NULL,
created_at timestamp NOT NULL
);
CREATE INDEX idx_user_medias_user_id ON user_medias (user_id);
CREATE INDEX idx_user_medias_tenant_id ON user_medias (tenant_id);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE users;
DROP TABLE tenants;
DROP TABLE users_tenants;
DROP TABLE tenant_user_balances;
DROP TABLE user_balance_histories;
DROP TABLE medias;
DROP TABLE media_resources;
DROP TABLE user_medias;
-- +goose StatementEnd

View File

@@ -1,23 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type MediaResources struct {
ID int64 `sql:"primary_key"`
MediaID int64
Type string
Source *string
Size int64
Publish bool
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@@ -1,24 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type Medias struct {
ID int64 `sql:"primary_key"`
TenantID int64
Title string
Description string
Price int64
Discount int64
Publish bool
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@@ -1,19 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type Migrations struct {
ID int32 `sql:"primary_key"`
VersionID int64
IsApplied bool
Tstamp time.Time
}

View File

@@ -1,15 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
type TenantUserBalances struct {
ID int64 `sql:"primary_key"`
UserID int64
TenantID int64
Balance int64
}

View File

@@ -1,22 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type Tenants struct {
ID int64 `sql:"primary_key"`
Name string
Slug string
Description *string
ExpireAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@@ -1,22 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type UserBalanceHistories struct {
ID int64 `sql:"primary_key"`
UserID int64
TenantID int64
Balance int64
Target *string
Type string
CreatedAt time.Time
}

View File

@@ -1,21 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type UserMedias struct {
ID int64 `sql:"primary_key"`
UserID int64
TenantID int64
MediaID int64
Price int64
CreatedAt time.Time
}

View File

@@ -1,22 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type Users struct {
ID int64 `sql:"primary_key"`
OpenID string
UnionID *string
OAuth *string
ExpireIn time.Time
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@@ -1,19 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type UsersTenants struct {
ID int64 `sql:"primary_key"`
UserID int64
TenantID int64
CreatedAt time.Time
}

View File

@@ -1,96 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var MediaResources = newMediaResourcesTable("public", "media_resources", "")
type mediaResourcesTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
MediaID postgres.ColumnInteger
Type postgres.ColumnString
Source postgres.ColumnString
Size postgres.ColumnInteger
Publish postgres.ColumnBool
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type MediaResourcesTable struct {
mediaResourcesTable
EXCLUDED mediaResourcesTable
}
// AS creates new MediaResourcesTable with assigned alias
func (a MediaResourcesTable) AS(alias string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new MediaResourcesTable with assigned schema name
func (a MediaResourcesTable) FromSchema(schemaName string) *MediaResourcesTable {
return newMediaResourcesTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new MediaResourcesTable with assigned table prefix
func (a MediaResourcesTable) WithPrefix(prefix string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new MediaResourcesTable with assigned table suffix
func (a MediaResourcesTable) WithSuffix(suffix string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newMediaResourcesTable(schemaName, tableName, alias string) *MediaResourcesTable {
return &MediaResourcesTable{
mediaResourcesTable: newMediaResourcesTableImpl(schemaName, tableName, alias),
EXCLUDED: newMediaResourcesTableImpl("", "excluded", ""),
}
}
func newMediaResourcesTableImpl(schemaName, tableName, alias string) mediaResourcesTable {
var (
IDColumn = postgres.IntegerColumn("id")
MediaIDColumn = postgres.IntegerColumn("media_id")
TypeColumn = postgres.StringColumn("type")
SourceColumn = postgres.StringColumn("source")
SizeColumn = postgres.IntegerColumn("size")
PublishColumn = postgres.BoolColumn("publish")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, MediaIDColumn, TypeColumn, SourceColumn, SizeColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{MediaIDColumn, TypeColumn, SourceColumn, SizeColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
)
return mediaResourcesTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
MediaID: MediaIDColumn,
Type: TypeColumn,
Source: SourceColumn,
Size: SizeColumn,
Publish: PublishColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,99 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Medias = newMediasTable("public", "medias", "")
type mediasTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
TenantID postgres.ColumnInteger
Title postgres.ColumnString
Description postgres.ColumnString
Price postgres.ColumnInteger
Discount postgres.ColumnInteger
Publish postgres.ColumnBool
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type MediasTable struct {
mediasTable
EXCLUDED mediasTable
}
// AS creates new MediasTable with assigned alias
func (a MediasTable) AS(alias string) *MediasTable {
return newMediasTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new MediasTable with assigned schema name
func (a MediasTable) FromSchema(schemaName string) *MediasTable {
return newMediasTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new MediasTable with assigned table prefix
func (a MediasTable) WithPrefix(prefix string) *MediasTable {
return newMediasTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new MediasTable with assigned table suffix
func (a MediasTable) WithSuffix(suffix string) *MediasTable {
return newMediasTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newMediasTable(schemaName, tableName, alias string) *MediasTable {
return &MediasTable{
mediasTable: newMediasTableImpl(schemaName, tableName, alias),
EXCLUDED: newMediasTableImpl("", "excluded", ""),
}
}
func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
var (
IDColumn = postgres.IntegerColumn("id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
TitleColumn = postgres.StringColumn("title")
DescriptionColumn = postgres.StringColumn("description")
PriceColumn = postgres.IntegerColumn("price")
DiscountColumn = postgres.IntegerColumn("discount")
PublishColumn = postgres.BoolColumn("publish")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
)
return mediasTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
TenantID: TenantIDColumn,
Title: TitleColumn,
Description: DescriptionColumn,
Price: PriceColumn,
Discount: DiscountColumn,
Publish: PublishColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,84 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Migrations = newMigrationsTable("public", "migrations", "")
type migrationsTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
VersionID postgres.ColumnInteger
IsApplied postgres.ColumnBool
Tstamp postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type MigrationsTable struct {
migrationsTable
EXCLUDED migrationsTable
}
// AS creates new MigrationsTable with assigned alias
func (a MigrationsTable) AS(alias string) *MigrationsTable {
return newMigrationsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new MigrationsTable with assigned schema name
func (a MigrationsTable) FromSchema(schemaName string) *MigrationsTable {
return newMigrationsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new MigrationsTable with assigned table prefix
func (a MigrationsTable) WithPrefix(prefix string) *MigrationsTable {
return newMigrationsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new MigrationsTable with assigned table suffix
func (a MigrationsTable) WithSuffix(suffix string) *MigrationsTable {
return newMigrationsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newMigrationsTable(schemaName, tableName, alias string) *MigrationsTable {
return &MigrationsTable{
migrationsTable: newMigrationsTableImpl(schemaName, tableName, alias),
EXCLUDED: newMigrationsTableImpl("", "excluded", ""),
}
}
func newMigrationsTableImpl(schemaName, tableName, alias string) migrationsTable {
var (
IDColumn = postgres.IntegerColumn("id")
VersionIDColumn = postgres.IntegerColumn("version_id")
IsAppliedColumn = postgres.BoolColumn("is_applied")
TstampColumn = postgres.TimestampColumn("tstamp")
allColumns = postgres.ColumnList{IDColumn, VersionIDColumn, IsAppliedColumn, TstampColumn}
mutableColumns = postgres.ColumnList{VersionIDColumn, IsAppliedColumn, TstampColumn}
)
return migrationsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
VersionID: VersionIDColumn,
IsApplied: IsAppliedColumn,
Tstamp: TstampColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,22 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
// UseSchema sets a new schema name for all generated table SQL builder types. It is recommended to invoke
// this method only once at the beginning of the program.
func UseSchema(schema string) {
MediaResources = MediaResources.FromSchema(schema)
Medias = Medias.FromSchema(schema)
Migrations = Migrations.FromSchema(schema)
TenantUserBalances = TenantUserBalances.FromSchema(schema)
Tenants = Tenants.FromSchema(schema)
UserBalanceHistories = UserBalanceHistories.FromSchema(schema)
UserMedias = UserMedias.FromSchema(schema)
Users = Users.FromSchema(schema)
UsersTenants = UsersTenants.FromSchema(schema)
}

View File

@@ -1,84 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var TenantUserBalances = newTenantUserBalancesTable("public", "tenant_user_balances", "")
type tenantUserBalancesTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
Balance postgres.ColumnInteger
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type TenantUserBalancesTable struct {
tenantUserBalancesTable
EXCLUDED tenantUserBalancesTable
}
// AS creates new TenantUserBalancesTable with assigned alias
func (a TenantUserBalancesTable) AS(alias string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new TenantUserBalancesTable with assigned schema name
func (a TenantUserBalancesTable) FromSchema(schemaName string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new TenantUserBalancesTable with assigned table prefix
func (a TenantUserBalancesTable) WithPrefix(prefix string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new TenantUserBalancesTable with assigned table suffix
func (a TenantUserBalancesTable) WithSuffix(suffix string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newTenantUserBalancesTable(schemaName, tableName, alias string) *TenantUserBalancesTable {
return &TenantUserBalancesTable{
tenantUserBalancesTable: newTenantUserBalancesTableImpl(schemaName, tableName, alias),
EXCLUDED: newTenantUserBalancesTableImpl("", "excluded", ""),
}
}
func newTenantUserBalancesTableImpl(schemaName, tableName, alias string) tenantUserBalancesTable {
var (
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
BalanceColumn = postgres.IntegerColumn("balance")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, BalanceColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, BalanceColumn}
)
return tenantUserBalancesTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
Balance: BalanceColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,93 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Tenants = newTenantsTable("public", "tenants", "")
type tenantsTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
Name postgres.ColumnString
Slug postgres.ColumnString
Description postgres.ColumnString
ExpireAt postgres.ColumnTimestamp
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type TenantsTable struct {
tenantsTable
EXCLUDED tenantsTable
}
// AS creates new TenantsTable with assigned alias
func (a TenantsTable) AS(alias string) *TenantsTable {
return newTenantsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new TenantsTable with assigned schema name
func (a TenantsTable) FromSchema(schemaName string) *TenantsTable {
return newTenantsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new TenantsTable with assigned table prefix
func (a TenantsTable) WithPrefix(prefix string) *TenantsTable {
return newTenantsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new TenantsTable with assigned table suffix
func (a TenantsTable) WithSuffix(suffix string) *TenantsTable {
return newTenantsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newTenantsTable(schemaName, tableName, alias string) *TenantsTable {
return &TenantsTable{
tenantsTable: newTenantsTableImpl(schemaName, tableName, alias),
EXCLUDED: newTenantsTableImpl("", "excluded", ""),
}
}
func newTenantsTableImpl(schemaName, tableName, alias string) tenantsTable {
var (
IDColumn = postgres.IntegerColumn("id")
NameColumn = postgres.StringColumn("name")
SlugColumn = postgres.StringColumn("slug")
DescriptionColumn = postgres.StringColumn("description")
ExpireAtColumn = postgres.TimestampColumn("expire_at")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, NameColumn, SlugColumn, DescriptionColumn, ExpireAtColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{NameColumn, SlugColumn, DescriptionColumn, ExpireAtColumn, CreatedAtColumn, UpdatedAtColumn}
)
return tenantsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
Name: NameColumn,
Slug: SlugColumn,
Description: DescriptionColumn,
ExpireAt: ExpireAtColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,93 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var UserBalanceHistories = newUserBalanceHistoriesTable("public", "user_balance_histories", "")
type userBalanceHistoriesTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
Balance postgres.ColumnInteger
Target postgres.ColumnString
Type postgres.ColumnString
CreatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type UserBalanceHistoriesTable struct {
userBalanceHistoriesTable
EXCLUDED userBalanceHistoriesTable
}
// AS creates new UserBalanceHistoriesTable with assigned alias
func (a UserBalanceHistoriesTable) AS(alias string) *UserBalanceHistoriesTable {
return newUserBalanceHistoriesTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new UserBalanceHistoriesTable with assigned schema name
func (a UserBalanceHistoriesTable) FromSchema(schemaName string) *UserBalanceHistoriesTable {
return newUserBalanceHistoriesTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new UserBalanceHistoriesTable with assigned table prefix
func (a UserBalanceHistoriesTable) WithPrefix(prefix string) *UserBalanceHistoriesTable {
return newUserBalanceHistoriesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new UserBalanceHistoriesTable with assigned table suffix
func (a UserBalanceHistoriesTable) WithSuffix(suffix string) *UserBalanceHistoriesTable {
return newUserBalanceHistoriesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newUserBalanceHistoriesTable(schemaName, tableName, alias string) *UserBalanceHistoriesTable {
return &UserBalanceHistoriesTable{
userBalanceHistoriesTable: newUserBalanceHistoriesTableImpl(schemaName, tableName, alias),
EXCLUDED: newUserBalanceHistoriesTableImpl("", "excluded", ""),
}
}
func newUserBalanceHistoriesTableImpl(schemaName, tableName, alias string) userBalanceHistoriesTable {
var (
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
BalanceColumn = postgres.IntegerColumn("balance")
TargetColumn = postgres.StringColumn("target")
TypeColumn = postgres.StringColumn("type")
CreatedAtColumn = postgres.TimestampColumn("created_at")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, BalanceColumn, TargetColumn, TypeColumn, CreatedAtColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, BalanceColumn, TargetColumn, TypeColumn, CreatedAtColumn}
)
return userBalanceHistoriesTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
Balance: BalanceColumn,
Target: TargetColumn,
Type: TypeColumn,
CreatedAt: CreatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,90 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var UserMedias = newUserMediasTable("public", "user_medias", "")
type userMediasTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
MediaID postgres.ColumnInteger
Price postgres.ColumnInteger
CreatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type UserMediasTable struct {
userMediasTable
EXCLUDED userMediasTable
}
// AS creates new UserMediasTable with assigned alias
func (a UserMediasTable) AS(alias string) *UserMediasTable {
return newUserMediasTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new UserMediasTable with assigned schema name
func (a UserMediasTable) FromSchema(schemaName string) *UserMediasTable {
return newUserMediasTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new UserMediasTable with assigned table prefix
func (a UserMediasTable) WithPrefix(prefix string) *UserMediasTable {
return newUserMediasTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new UserMediasTable with assigned table suffix
func (a UserMediasTable) WithSuffix(suffix string) *UserMediasTable {
return newUserMediasTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newUserMediasTable(schemaName, tableName, alias string) *UserMediasTable {
return &UserMediasTable{
userMediasTable: newUserMediasTableImpl(schemaName, tableName, alias),
EXCLUDED: newUserMediasTableImpl("", "excluded", ""),
}
}
func newUserMediasTableImpl(schemaName, tableName, alias string) userMediasTable {
var (
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
MediaIDColumn = postgres.IntegerColumn("media_id")
PriceColumn = postgres.IntegerColumn("price")
CreatedAtColumn = postgres.TimestampColumn("created_at")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, MediaIDColumn, PriceColumn, CreatedAtColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, MediaIDColumn, PriceColumn, CreatedAtColumn}
)
return userMediasTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
MediaID: MediaIDColumn,
Price: PriceColumn,
CreatedAt: CreatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,93 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Users = newUsersTable("public", "users", "")
type usersTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
OpenID postgres.ColumnString
UnionID postgres.ColumnString
OAuth postgres.ColumnString
ExpireIn postgres.ColumnTimestamp
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type UsersTable struct {
usersTable
EXCLUDED usersTable
}
// AS creates new UsersTable with assigned alias
func (a UsersTable) AS(alias string) *UsersTable {
return newUsersTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new UsersTable with assigned schema name
func (a UsersTable) FromSchema(schemaName string) *UsersTable {
return newUsersTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new UsersTable with assigned table prefix
func (a UsersTable) WithPrefix(prefix string) *UsersTable {
return newUsersTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new UsersTable with assigned table suffix
func (a UsersTable) WithSuffix(suffix string) *UsersTable {
return newUsersTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newUsersTable(schemaName, tableName, alias string) *UsersTable {
return &UsersTable{
usersTable: newUsersTableImpl(schemaName, tableName, alias),
EXCLUDED: newUsersTableImpl("", "excluded", ""),
}
}
func newUsersTableImpl(schemaName, tableName, alias string) usersTable {
var (
IDColumn = postgres.IntegerColumn("id")
OpenIDColumn = postgres.StringColumn("open_id")
UnionIDColumn = postgres.StringColumn("union_id")
OAuthColumn = postgres.StringColumn("oauth")
ExpireInColumn = postgres.TimestampColumn("expire_in")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, OpenIDColumn, UnionIDColumn, OAuthColumn, ExpireInColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{OpenIDColumn, UnionIDColumn, OAuthColumn, ExpireInColumn, CreatedAtColumn, UpdatedAtColumn}
)
return usersTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
OpenID: OpenIDColumn,
UnionID: UnionIDColumn,
OAuth: OAuthColumn,
ExpireIn: ExpireInColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,84 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var UsersTenants = newUsersTenantsTable("public", "users_tenants", "")
type usersTenantsTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
CreatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type UsersTenantsTable struct {
usersTenantsTable
EXCLUDED usersTenantsTable
}
// AS creates new UsersTenantsTable with assigned alias
func (a UsersTenantsTable) AS(alias string) *UsersTenantsTable {
return newUsersTenantsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new UsersTenantsTable with assigned schema name
func (a UsersTenantsTable) FromSchema(schemaName string) *UsersTenantsTable {
return newUsersTenantsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new UsersTenantsTable with assigned table prefix
func (a UsersTenantsTable) WithPrefix(prefix string) *UsersTenantsTable {
return newUsersTenantsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new UsersTenantsTable with assigned table suffix
func (a UsersTenantsTable) WithSuffix(suffix string) *UsersTenantsTable {
return newUsersTenantsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newUsersTenantsTable(schemaName, tableName, alias string) *UsersTenantsTable {
return &UsersTenantsTable{
usersTenantsTable: newUsersTenantsTableImpl(schemaName, tableName, alias),
EXCLUDED: newUsersTenantsTableImpl("", "excluded", ""),
}
}
func newUsersTenantsTableImpl(schemaName, tableName, alias string) usersTenantsTable {
var (
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
CreatedAtColumn = postgres.TimestampColumn("created_at")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, CreatedAtColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, CreatedAtColumn}
)
return usersTenantsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
CreatedAt: CreatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -1,71 +0,0 @@
module git.ipao.vip/rogeecn/mp-qvyun
go 1.23.2
require (
github.com/go-jet/jet/v2 v2.12.0
github.com/gofiber/fiber/v3 v3.0.0-beta.3
github.com/imroc/req/v3 v3.48.0
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/pressly/goose/v3 v3.23.0
github.com/sirupsen/logrus v1.9.3
github.com/smartystreets/goconvey v1.8.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
go.uber.org/dig v1.18.0
)
require (
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/cloudflare/circl v1.4.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.47.0 // indirect
github.com/refraction-networking/utls v1.6.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/smarty/assertions v1.15.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.25.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,189 +0,0 @@
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/cloudflare/circl v1.4.0 h1:BV7h5MgrktNzytKmWjpOtdYrf0lkkbF8YMlBGPhJQrY=
github.com/cloudflare/circl v1.4.0/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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 h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-jet/jet/v2 v2.12.0 h1:z2JfvBAZgsfxlQz6NXBYdZTXc7ep3jhbszTLtETv1JE=
github.com/go-jet/jet/v2 v2.12.0/go.mod h1:ufQVRQeI1mbcO5R8uCEVcVf3Foej9kReBdwDx7YMWUM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gofiber/fiber/v3 v3.0.0-beta.3 h1:7Q2I+HsIqnIEEDB+9oe7Gadpakh6ZLhXpTYz/L20vrg=
github.com/gofiber/fiber/v3 v3.0.0-beta.3/go.mod h1:kcMur0Dxqk91R7p4vxEpJfDWZ9u5IfvrtQc8Bvv/JmY=
github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co=
github.com/gofiber/utils/v2 v2.0.0-beta.4/go.mod h1:sdRsPU1FXX6YiDGGxd+q2aPJRMzpsxdzCXo9dz+xtOY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 h1:c5FlPPgxOn7kJz3VoPLkQYQXGBS3EklQ4Zfi57uOuqQ=
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/imroc/req/v3 v3.48.0 h1:IYuMGetuwLzOOTzDCquDqs912WNwpsPK0TBXWPIvoqg=
github.com/imroc/req/v3 v3.48.0/go.mod h1:weam9gmyb00QnOtu6HXSnk44dNFkIUQb5QdMx13FeUU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pressly/goose/v3 v3.23.0 h1:57hqKos8izGek4v6D5+OXBa+Y4Rq8MU//+MmnevdpVA=
github.com/pressly/goose/v3 v3.23.0/go.mod h1:rpx+D9GX/+stXmzKa+uh1DkjPnNVMdiOCV9iLdle4N8=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.47.0 h1:yXs3v7r2bm1wmPTYNLKAAJTHMYkPEsfYJmTazXrCZ7Y=
github.com/quic-go/quic-go v0.47.0/go.mod h1:3bCapYsJvXGZcipOHuu7plYtaV6tnF+z7wIFsU0WK9E=
github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM=
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
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=
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
modernc.org/sqlite v1.34.1 h1:u3Yi6M0N8t9yKRDwhXcyp1eS5/ErhPTBggxWFuR6Hfk=
modernc.org/sqlite v1.34.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

View File

@@ -1,43 +0,0 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package main
import (
"log"
"git.ipao.vip/rogeecn/mp-qvyun/cmd"
"git.ipao.vip/rogeecn/mp-qvyun/conf"
"github.com/spf13/cobra"
)
func init() {
}
func main() {
rootCmd := &cobra.Command{
Use: "qvyun",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := conf.Load(cmd.Flag("config").Value.String()); err != nil {
return err
}
if cmd.Flag("debug").Value.String() == "true" {
conf.C.Debug = true
}
return nil
},
}
rootCmd.PersistentFlags().StringP("config", "C", "", "config file")
rootCmd.PersistentFlags().BoolP("debug", "D", false, "debug mode")
cmd.CommandServe(rootCmd)
cmd.CommandMigrate(rootCmd)
err := rootCmd.Execute()
if err != nil {
log.Fatal(err)
}
}

View File

@@ -1 +0,0 @@
package medias

View File

@@ -1 +0,0 @@
package users

View File

@@ -1,7 +0,0 @@
package medias
import "github.com/gofiber/fiber/v3"
func GetMedias(c fiber.Ctx) error {
return c.SendString("medias")
}

View File

@@ -1,7 +0,0 @@
package medias
import "github.com/gofiber/fiber/v3"
func RegisterRoutes(app fiber.App) {
app.Get("/medias", GetMedias)
}

View File

@@ -1,15 +0,0 @@
package users
import "github.com/gofiber/fiber/v3"
type UserController struct {
userSvc *UserService
}
func GetUsers(c fiber.Ctx) error {
return c.SendString("users")
}
func GetCurrentUserInfo(c fiber.Ctx) error {
return c.SendString("current user info")
}

View File

@@ -1,6 +0,0 @@
package users
type CurrentUserInfo struct {
OpenID string `json:"open_id"`
Balance int8 `json:"balance"`
}

View File

@@ -1 +0,0 @@
package users

View File

@@ -1,10 +0,0 @@
package users
import "github.com/gofiber/fiber/v3"
func RegisterRoutes(app *fiber.App) {
group := app.Group("users")
// 获取当前用户信息
group.Get("/self", GetCurrentUserInfo)
}

View File

@@ -1,7 +0,0 @@
package users
type UserService struct{}
func (svc *UserService) GetUsers() string {
return "users"
}

View File

@@ -1,75 +0,0 @@
package container
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
"git.ipao.vip/rogeecn/mp-qvyun/pkg/opt"
"github.com/spf13/viper"
"go.uber.org/dig"
)
var (
Container *dig.Container = dig.New()
Cancel context.CancelFunc
closeable []func()
)
func init() {
closeable = make([]func(), 0)
if err := Container.Provide(func() context.Context {
signals := []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL}
ctx, cancel := signal.NotifyContext(context.Background(), signals...)
go func() {
<-ctx.Done()
go time.AfterFunc(time.Second*5, func() {
os.Exit(1)
})
Close()
Cancel()
}()
Cancel = cancel
return ctx
}); err != nil {
log.Fatal(err)
}
}
func AddCloseAble(c func()) {
closeable = append(closeable, c)
}
func Close() {
for _, c := range closeable {
c()
}
}
type ProviderContainer struct {
Provider func(...opt.Option) error
Options []opt.Option
}
type Providers []ProviderContainer
func (p Providers) With(pcs ...Providers) Providers {
for _, pc := range pcs {
p = append(p, pc...)
}
return p
}
func (p Providers) Provide(config *viper.Viper) error {
for _, provider := range p {
provider.Options = append(provider.Options, opt.Config(config))
if err := provider.Provider(provider.Options...); err != nil {
return err
}
}
return nil
}

View File

@@ -1,5 +0,0 @@
package contracts
import "github.com/gofiber/fiber/v3"
type WithRoutes func(r *fiber.App)

View File

@@ -1,100 +0,0 @@
package fiberv3
import (
"git.ipao.vip/rogeecn/mp-qvyun/pkg/wechat"
"github.com/gofiber/fiber/v3"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
type fiberMiddlewares struct {
client *wechat.Client
}
func Init(client *wechat.Client) *fiberMiddlewares {
return &fiberMiddlewares{
client: client,
}
}
func (f *fiberMiddlewares) Verify(c fiber.Ctx) error {
// get the query parameters
signature := c.Query("signature")
timestamp := c.Query("timestamp")
nonce := c.Query("nonce")
echostr := c.Query("echostr")
if signature == "" || timestamp == "" || nonce == "" || echostr == "" {
return c.Next()
}
log.Infof(
"begin verify signature, signature: %s, timestamp: %s, nonce: %s, echostr: %s",
signature,
timestamp,
nonce,
echostr,
)
// verify the signature
if err := f.client.Verify(signature, timestamp, nonce); err != nil {
return c.SendString(err.Error())
}
return c.SendString(echostr)
}
func (f *fiberMiddlewares) SilentAuth(c fiber.Ctx) error {
// if cookie not exists key "openid", then redirect to the wechat auth page
sid := c.Cookies("sid", "")
if sid != "" {
// TODO: verify sid
return c.Next()
}
// get current full url
url := c.BaseURL()
url = "https://qvyun.mp.jdwan.com"
log.WithField("module", "middleware.SilentAuth").Debug("url:", url)
to, err := f.client.ScopeAuthorizeURL(
wechat.ScopeAuthorizeURLWithRedirectURI(url),
wechat.ScopeAuthorizeURLWithState("sns_basic_auth"),
)
if err != nil {
return errors.Wrap(err, "failed to get wechat auth url")
}
log.WithField("module", "middleware.SilentAuth").Debug("redirectTo: ", to.String())
return c.Redirect().To(to.String())
}
func (f *fiberMiddlewares) AuthUserInfo(c fiber.Ctx) error {
state := c.Query("state")
code := c.Query("code")
if state == "" && code == "" {
return c.Next()
}
if state != "sns_basic_auth" {
return c.Next()
}
log.WithField("module", "middleware.AuthUserInfo").Debug("code", code)
// get the openid
token, err := f.client.AuthorizeCode2Token(code)
if err != nil {
return errors.Wrap(err, "failed to get openid")
}
// TODO: store the openid to the session
// set the openid to the cookie
c.Cookie(&fiber.Cookie{
Name: "sid",
Value: token.Openid,
HTTPOnly: true,
})
return c.Redirect().To("/")
}

View File

@@ -1,62 +0,0 @@
package opt
import (
"github.com/spf13/viper"
"go.uber.org/dig"
)
type Options struct {
Config *viper.Viper
Prefix string
Name string
Group string
}
type Option func(o *Options)
func New(opts ...Option) *Options {
o := &Options{}
for _, opt := range opts {
opt(o)
}
return o
}
func (o *Options) UnmarshalConfig(config interface{}) error {
return o.Config.UnmarshalKey(o.Prefix, &config)
}
func (o *Options) DiOptions() []dig.ProvideOption {
options := []dig.ProvideOption{}
if o.Name != "" {
options = append(options, dig.Name(o.Name))
}
if o.Group != "" {
options = append(options, dig.Group(o.Group))
}
return options
}
func Config(config *viper.Viper) Option {
return func(o *Options) {
o.Config = config
}
}
func Name(name string) Option {
return func(o *Options) {
o.Name = name
}
}
func Group(group string) Option {
return func(o *Options) {
o.Group = group
}
}
func Prefix(prefix string) Option {
return func(o *Options) {
o.Prefix = prefix
}
}

View File

@@ -1,55 +0,0 @@
package wechat
import "github.com/pkg/errors"
// -1 系统繁忙,此时请开发者稍候再试
// 0 请求成功
// 40001 AppSecret错误或者AppSecret不属于这个公众号请开发者确认AppSecret的正确性
// 40002 请确保grant_type字段值为client_credential
// 40164 调用接口的IP地址不在白名单中请在接口IP白名单中进行设置。
// 40243 AppSecret已被冻结请登录MP解冻后再次调用。
// 89503 此IP调用需要管理员确认,请联系管理员
// 89501 此IP正在等待管理员确认,请联系管理员
// 89506 24小时内该IP被管理员拒绝调用两次24小时内不可再使用该IP调用
// 89507 1小时内该IP被管理员拒绝调用一次1小时内不可再使用该IP调用
// 10003 redirect_uri域名与后台配置不一致
// 10004 此公众号被封禁
// 10005 此公众号并没有这些scope的权限
// 10006 必须关注此测试号
// 10009 操作太频繁了,请稍后重试
// 10010 scope不能为空
// 10011 redirect_uri不能为空
// 10012 appid不能为空
// 10013 state不能为空
// 10015 公众号未授权第三方平台,请检查授权状态
// 10016 不支持微信开放平台的Appid请使用公众号Appid
func translateError(errCode int) error {
errors := map[int]error{
0: nil,
-1: errors.New("系统繁忙,此时请开发者稍候再试"),
40001: errors.New("AppSecret错误或者AppSecret不属于这个公众号请开发者确认AppSecret的正确性"),
40002: errors.New("请确保grant_type字段值为client_credential"),
40164: errors.New("调用接口的IP地址不在白名单中请在接口IP白名单中进行设置"),
40243: errors.New("AppSecret已被冻结请登录MP解冻后再次调用"),
89503: errors.New("此IP调用需要管理员确认,请联系管理员"),
89501: errors.New("此IP正在等待管理员确认,请联系管理员"),
89506: errors.New("24小时内该IP被管理员拒绝调用两次24小时内不可再使用该IP调用"),
89507: errors.New("1小时内该IP被管理员拒绝调用一次1小时内不可再使用该IP调用"),
10003: errors.New("redirect_uri域名与后台配置不一致"),
10004: errors.New("此公众号被封禁"),
10005: errors.New("此公众号并没有这些scope的权限"),
10006: errors.New("必须关注此测试号"),
10009: errors.New("操作太频繁了,请稍后重试"),
10010: errors.New("scope不能为空"),
10011: errors.New("redirect_uri不能为空"),
10012: errors.New("appid不能为空"),
10013: errors.New("state不能为空"),
10015: errors.New("公众号未授权第三方平台,请检查授权状态"),
10016: errors.New("不支持微信开放平台的Appid请使用公众号Appid"),
}
if err, ok := errors[errCode]; ok {
return err
}
return nil
}

View File

@@ -1,14 +0,0 @@
package wechat
import "math/rand"
// RandomString generate random size string
func randomString(size int) (string, error) {
// generate size string [0-9a-zA-Z]
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, size)
for i := range b {
b[i] = chars[rand.Intn(len(chars))]
}
return string(b), nil
}

View File

@@ -1,69 +0,0 @@
package wechat
import (
"net/url"
"github.com/imroc/req/v3"
)
type Options func(*Client)
func WithAppID(appID string) Options {
return func(we *Client) {
we.appID = appID
}
}
// WithAppSecret sets the app secret
func WithAppSecret(appSecret string) Options {
return func(we *Client) {
we.appSecret = appSecret
}
}
// WithToken sets the token
func WithToken(token string) Options {
return func(we *Client) {
we.token = token
}
}
// WithAESKey sets the AES key
func WithAESKey(aesKey string) Options {
return func(we *Client) {
we.aesKey = aesKey
}
}
// WithClient sets the http client
func WithClient(client *req.Client) Options {
return func(we *Client) {
we.client = client
}
}
type ScopeAuthorizeURLOptions func(url.Values)
func ScopeAuthorizeURLWithScope(scope AuthScope) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("scope", scope.String())
}
}
func ScopeAuthorizeURLWithRedirectURI(uri string) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("redirect_uri", uri)
}
}
func ScopeAuthorizeURLWithState(state string) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("state", state)
}
}
func ScopeAuthorizeURLWithForcePopup() ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("forcePopup", "true")
}
}

View File

@@ -1,16 +0,0 @@
package wechat
type Response struct {
ErrCode int `json:"errcode"`
ErrMsg int `json:"errmsg"`
ErrDescribe int `json:"-"`
}
func (r *Response) Error() error {
return translateError(r.ErrCode)
}
type AccessTokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"` // seconds
}

View File

@@ -1,182 +0,0 @@
package wechat
import (
"crypto/sha1"
"encoding/hex"
"net/url"
"sort"
"strings"
"github.com/imroc/req/v3"
"github.com/pkg/errors"
)
const BaseURL = "https://api.weixin.qq.com/"
var DefaultClient = req.
NewClient().
SetBaseURL(BaseURL).
SetCommonHeader("Content-Type", "application/json")
const (
ScopeBase = "snsapi_base"
ScopeUserInfo = "snsapi_userinfo"
)
type AuthScope string
func (s AuthScope) String() string {
return string(s)
}
type Client struct {
client *req.Client
appID string
appSecret string
token string
aesKey string
}
func New(options ...Options) *Client {
we := &Client{
client: DefaultClient,
}
for _, opt := range options {
opt(we)
}
return we
}
func (we *Client) Verify(signature, timestamp, nonce string) error {
params := []string{signature, timestamp, nonce, we.token}
sort.Strings(params)
str := strings.Join(params, "")
hash := sha1.Sum([]byte(str))
hashStr := hex.EncodeToString(hash[:])
if hashStr == signature {
return errors.New("Signature verification failed")
}
return nil
}
func (we *Client) wrapParams(params map[string]string) map[string]string {
if params == nil {
params = make(map[string]string)
}
params["appid"] = we.appID
params["secret"] = we.appSecret
return params
}
func (we *Client) GetAccessToken() (*AccessTokenResponse, error) {
params := map[string]string{
"grant_type": "client_credential",
}
var data AccessTokenResponse
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/cgi-bin/token")
if err != nil {
return nil, errors.Wrap(err, "call /cgi-bin/token failed")
}
return &data, nil
}
// ScopeAuthorizeURL
func (we *Client) ScopeAuthorizeURL(opts ...ScopeAuthorizeURLOptions) (*url.URL, error) {
params := url.Values{}
params.Add("appid", we.appID)
params.Add("response_type", "code")
for _, opt := range opts {
opt(params)
}
if params.Get("scope") == "" {
params.Add("scope", ScopeBase)
}
u, err := url.Parse("https://open.weixin.qq.com/connect/oauth2/authorize")
if err != nil {
return nil, errors.Wrap(err, "parse url failed")
}
u.Fragment = "wechat_redirect"
u.RawQuery = url.Values(params).Encode()
return u, nil
}
type AuthorizeAccessToken struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
IsSnapshotuser int64 `json:"is_snapshotuser"`
Openid string `json:"openid"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
Unionid string `json:"unionid"`
}
func (we *Client) AuthorizeCode2Token(code string) (*AuthorizeAccessToken, error) {
params := we.wrapParams(map[string]string{
"code": code,
"grant_type": "authorization_code",
})
var data AuthorizeAccessToken
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/sns/oauth2/access_token")
if err != nil {
return nil, errors.Wrap(err, "call /sns/oauth2/access_token failed")
}
return &data, nil
}
func (we *Client) AuthorizeRefreshAccessToken(accessToken string) (*AuthorizeAccessToken, error) {
params := we.wrapParams(map[string]string{
"refresh_token": accessToken,
"grant_type": "refresh_token",
})
var data AuthorizeAccessToken
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/sns/oauth2/refresh_token")
if err != nil {
return nil, errors.Wrap(err, "call /sns/oauth2/refresh_token failed")
}
return &data, nil
}
type AuthorizeUserInfo struct {
City string `json:"city"`
Country string `json:"country"`
Headimgurl string `json:"headimgurl"`
Nickname string `json:"nickname"`
Openid string `json:"openid"`
Privilege []string `json:"privilege"`
Province string `json:"province"`
Sex int64 `json:"sex"`
Unionid string `json:"unionid"`
}
func (we *Client) AuthorizeUserInfo(accessToken, openID string) (*AuthorizeUserInfo, error) {
params := (map[string]string{
"access_token": accessToken,
"openid": openID,
})
var data AuthorizeUserInfo
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/sns/userinfo")
if err != nil {
return nil, errors.Wrap(err, "call /sns/userinfo failed")
}
return &data, nil
}

View File

@@ -1,86 +0,0 @@
package wechat
import (
"testing"
log "github.com/sirupsen/logrus"
. "github.com/smartystreets/goconvey/convey"
)
const (
WechatAppID = "wx45745a8c51091ae0"
WechatAppSecret = "2ab33bc79d9b47efa4abef19d66e1977"
WechatToken = "W8Xhw5TivYBgY"
WechatAesKey = "F6AqCxAV4W1eCrY6llJ2zapphKK49CQN3RgtPDrjhnI"
)
func init() {
log.SetLevel(log.DebugLevel)
}
func getClient() *Client {
return New(
WithAppID(WechatAppID),
WithAppSecret(WechatAppSecret),
WithAESKey(WechatAesKey),
WithToken(WechatToken),
WithClient(DefaultClient.DevMode()),
)
}
func TestWechatClient_GetAccessToken(t *testing.T) {
Convey("Test GetAccessToken", t, func() {
token, err := getClient().GetAccessToken()
So(err, ShouldBeNil)
So(token.AccessToken, ShouldNotBeEmpty)
So(token.ExpiresIn, ShouldBeGreaterThan, 0)
t.Log("Access Token:", token.AccessToken)
})
}
func TestClient_ScopeAuthorizeURL(t *testing.T) {
Convey("Test ScopeAuthorizeURL", t, func() {
url, err := getClient().ScopeAuthorizeURL(
ScopeAuthorizeURLWithScope(ScopeBase),
ScopeAuthorizeURLWithRedirectURI("https://qvyun.mp.jdwan.com/"),
)
So(err, ShouldBeNil)
So(url, ShouldNotBeEmpty)
t.Log("URL:", url)
})
}
func TestClient_AuthorizeCode2Token(t *testing.T) {
code := "011W1sll2Xv4Ae4OjUnl2I7jvd2W1slX"
Convey("Test AuthorizeCode2Token", t, func() {
token, err := getClient().AuthorizeCode2Token(code)
So(err, ShouldBeNil)
t.Logf("token: %+v", token)
})
}
func TestClient_AuthorizeRefreshAccessToken(t *testing.T) {
token := "86_m_EAHq0RKlo6RzzGAsY8gVmiCqHqIiAJufxhm8mK8imyIW6yoE4NTcIr2vaukp7dexPWId0JWP1iZWYaLpXT_MJv1N7YQW8Qt3zOZDpJY90"
Convey("Test AuthorizeCode2Token", t, func() {
token, err := getClient().AuthorizeRefreshAccessToken(token)
So(err, ShouldBeNil)
t.Logf("token: %+v", token)
})
}
func TestClient_AuthorizeUserInfo(t *testing.T) {
token := "86_ZxJa8mIwbml5mDlHHbIUle_UKW8LA75nOuB0wqiome8AX5LlMWU8JwRKMZykdLEjDnKX8EJavz5GeQn3T1ot7TwpULp8imQvNIgFIjC4er8"
openID := "oMLa5tyJ2vRHa-HI4CMEkHztq3eU"
Convey("Test AuthorizeUserInfo", t, func() {
user, err := getClient().AuthorizeUserInfo(token, openID)
So(err, ShouldBeNil)
t.Logf("user: %+v", user)
})
}

View File

@@ -5,9 +5,6 @@
},
{
"path": "backend"
},
{
"path": "backend_v1"
}
],
"settings": {