mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
commit
44e51e966a
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/DATA-DOG/go-sqlmock v1.5.0
|
||||
github.com/adshao/go-binance/v2 v2.3.5
|
||||
github.com/c9s/requestgen v1.1.1-0.20211230171502-c042072e23cd
|
||||
github.com/c9s/rockhopper v1.2.1-0.20210217093258-2661955904a9
|
||||
github.com/c9s/rockhopper v1.2.1-0.20220426104534-f27cbb09846c
|
||||
github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/gin-contrib/cors v1.3.1
|
||||
|
|
13
go.sum
13
go.sum
|
@ -70,6 +70,8 @@ github.com/c9s/requestgen v1.1.1-0.20211230171502-c042072e23cd h1:o87kZ8aHtxA1Zd
|
|||
github.com/c9s/requestgen v1.1.1-0.20211230171502-c042072e23cd/go.mod h1:5n9FU3hr5307IiXAmbMiZbHYaPiys1u9jCWYexZr9qA=
|
||||
github.com/c9s/rockhopper v1.2.1-0.20210217093258-2661955904a9 h1:Wlr5DjDOf5Kygoo0LoUthxwAhNwLEXMWHqCKXbMHCsw=
|
||||
github.com/c9s/rockhopper v1.2.1-0.20210217093258-2661955904a9/go.mod h1:KJnQjZSrWA83jjwGF/+O7Y96VCVirYTYEvXJJOc6kMU=
|
||||
github.com/c9s/rockhopper v1.2.1-0.20220426104534-f27cbb09846c h1:I3AHs+/fxnWX6eSRxzqQ/vp4jXW+ecVMGy1oy5d6fJ8=
|
||||
github.com/c9s/rockhopper v1.2.1-0.20220426104534-f27cbb09846c/go.mod h1:EKObf66Cp7erWxym2de+07qNN5T1N9PXxHdh97N44EQ=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
|
@ -162,6 +164,7 @@ github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
|
|||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8=
|
||||
github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
|
||||
|
@ -232,6 +235,7 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf
|
|||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
|
@ -272,6 +276,7 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
|
|||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
|
||||
|
@ -374,15 +379,21 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
|
|||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
|
||||
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
|
||||
|
@ -619,9 +630,11 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
|
|||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
|
||||
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
|
|
|
@ -2,6 +2,7 @@ package mysql
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
@ -10,6 +11,26 @@ import (
|
|||
|
||||
var registeredGoMigrations map[int64]*rockhopper.Migration
|
||||
|
||||
func MergeMigrationsMap(ms map[int64]*rockhopper.Migration) {
|
||||
for k, m := range ms {
|
||||
if _, ok := registeredGoMigrations[k]; !ok {
|
||||
registeredGoMigrations[k] = m
|
||||
} else {
|
||||
log.Printf("the migration key %d is duplicated: %+v", k, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetMigrationsMap() map[int64]*rockhopper.Migration {
|
||||
return registeredGoMigrations
|
||||
}
|
||||
|
||||
// SortedMigrations builds up the migration objects, sort them by timestamp and return as a slice
|
||||
func SortedMigrations() rockhopper.MigrationSlice {
|
||||
return Migrations()
|
||||
}
|
||||
|
||||
// Migrations builds up the migration objects, sort them by timestamp and return as a slice
|
||||
func Migrations() rockhopper.MigrationSlice {
|
||||
var migrations = rockhopper.MigrationSlice{}
|
||||
for _, migration := range registeredGoMigrations {
|
||||
|
@ -19,21 +40,28 @@ func Migrations() rockhopper.MigrationSlice {
|
|||
return migrations.SortAndConnect()
|
||||
}
|
||||
|
||||
// AddMigration adds a migration.
|
||||
// AddMigration adds a migration with its runtime caller information
|
||||
func AddMigration(up, down rockhopper.TransactionHandler) {
|
||||
pc, filename, _, _ := runtime.Caller(1)
|
||||
|
||||
funcName := runtime.FuncForPC(pc).Name()
|
||||
packageName := _parseFuncPackageName(funcName)
|
||||
AddNamedMigration(packageName, filename, up, down)
|
||||
}
|
||||
|
||||
// parseFuncPackageName parses the package name from a given runtime caller function name
|
||||
func _parseFuncPackageName(funcName string) string {
|
||||
lastSlash := strings.LastIndexByte(funcName, '/')
|
||||
if lastSlash < 0 {
|
||||
lastSlash = 0
|
||||
}
|
||||
|
||||
lastDot := strings.LastIndexByte(funcName[lastSlash:], '.') + lastSlash
|
||||
packageName := funcName[:lastDot]
|
||||
AddNamedMigration(packageName, filename, up, down)
|
||||
return packageName
|
||||
}
|
||||
|
||||
// AddNamedMigration : Add a named migration.
|
||||
// AddNamedMigration adds a named migration to the registered go migration map
|
||||
func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) {
|
||||
if registeredGoMigrations == nil {
|
||||
registeredGoMigrations = make(map[int64]*rockhopper.Migration)
|
||||
|
|
20
pkg/migrations/mysql/migration_api_test.go
Normal file
20
pkg/migrations/mysql/migration_api_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/c9s/rockhopper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetMigrationsMap(t *testing.T) {
|
||||
mm := GetMigrationsMap()
|
||||
assert.NotEmpty(t, mm)
|
||||
}
|
||||
|
||||
func TestMergeMigrationsMap(t *testing.T) {
|
||||
MergeMigrationsMap(map[int64]*rockhopper.Migration{
|
||||
2: &rockhopper.Migration{},
|
||||
3: &rockhopper.Migration{},
|
||||
})
|
||||
}
|
|
@ -2,6 +2,7 @@ package sqlite3
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
|
@ -10,6 +11,26 @@ import (
|
|||
|
||||
var registeredGoMigrations map[int64]*rockhopper.Migration
|
||||
|
||||
func MergeMigrationsMap(ms map[int64]*rockhopper.Migration) {
|
||||
for k, m := range ms {
|
||||
if _, ok := registeredGoMigrations[k]; !ok {
|
||||
registeredGoMigrations[k] = m
|
||||
} else {
|
||||
log.Printf("the migration key %d is duplicated: %+v", k, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetMigrationsMap() map[int64]*rockhopper.Migration {
|
||||
return registeredGoMigrations
|
||||
}
|
||||
|
||||
// SortedMigrations builds up the migration objects, sort them by timestamp and return as a slice
|
||||
func SortedMigrations() rockhopper.MigrationSlice {
|
||||
return Migrations()
|
||||
}
|
||||
|
||||
// Migrations builds up the migration objects, sort them by timestamp and return as a slice
|
||||
func Migrations() rockhopper.MigrationSlice {
|
||||
var migrations = rockhopper.MigrationSlice{}
|
||||
for _, migration := range registeredGoMigrations {
|
||||
|
@ -19,21 +40,28 @@ func Migrations() rockhopper.MigrationSlice {
|
|||
return migrations.SortAndConnect()
|
||||
}
|
||||
|
||||
// AddMigration adds a migration.
|
||||
// AddMigration adds a migration with its runtime caller information
|
||||
func AddMigration(up, down rockhopper.TransactionHandler) {
|
||||
pc, filename, _, _ := runtime.Caller(1)
|
||||
|
||||
funcName := runtime.FuncForPC(pc).Name()
|
||||
packageName := _parseFuncPackageName(funcName)
|
||||
AddNamedMigration(packageName, filename, up, down)
|
||||
}
|
||||
|
||||
// parseFuncPackageName parses the package name from a given runtime caller function name
|
||||
func _parseFuncPackageName(funcName string) string {
|
||||
lastSlash := strings.LastIndexByte(funcName, '/')
|
||||
if lastSlash < 0 {
|
||||
lastSlash = 0
|
||||
}
|
||||
|
||||
lastDot := strings.LastIndexByte(funcName[lastSlash:], '.') + lastSlash
|
||||
packageName := funcName[:lastDot]
|
||||
AddNamedMigration(packageName, filename, up, down)
|
||||
return packageName
|
||||
}
|
||||
|
||||
// AddNamedMigration : Add a named migration.
|
||||
// AddNamedMigration adds a named migration to the registered go migration map
|
||||
func AddNamedMigration(packageName, filename string, up, down rockhopper.TransactionHandler) {
|
||||
if registeredGoMigrations == nil {
|
||||
registeredGoMigrations = make(map[int64]*rockhopper.Migration)
|
||||
|
|
20
pkg/migrations/sqlite3/migration_api_test.go
Normal file
20
pkg/migrations/sqlite3/migration_api_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package sqlite3
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/c9s/rockhopper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetMigrationsMap(t *testing.T) {
|
||||
mm := GetMigrationsMap()
|
||||
assert.NotEmpty(t, mm)
|
||||
}
|
||||
|
||||
func TestMergeMigrationsMap(t *testing.T) {
|
||||
MergeMigrationsMap(map[int64]*rockhopper.Migration{
|
||||
2: &rockhopper.Migration{},
|
||||
3: &rockhopper.Migration{},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user