├── .gitignore ├── assets └── GO-STARTER.png ├── common ├── functions │ ├── app.go │ ├── app_test.go │ ├── app_impl.go │ └── mock │ │ └── app_mocks.go └── code │ ├── error_code.go │ ├── gen │ ├── settings.yaml │ ├── settings.toml │ └── settings.json │ ├── config_reader_code.go │ ├── compose_gen_test.go │ ├── config_code_test.go │ ├── config_code.go │ ├── main_code.go │ ├── compose_gen.go │ ├── db_code.go │ └── dependencies_code.go ├── helpers ├── error.go ├── version.go ├── version_test.go └── yaml.go ├── go.mod ├── main.go ├── app └── app.go ├── go.sum └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | app.md 3 | test/ 4 | common/code/gen -------------------------------------------------------------------------------- /assets/GO-STARTER.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanchann/go-starter/HEAD/assets/GO-STARTER.png -------------------------------------------------------------------------------- /common/functions/app.go: -------------------------------------------------------------------------------- 1 | package functions 2 | 3 | type IAppPathGenerator interface { 4 | CreateAppPath(path string) error 5 | GenerateAppCode(code string) error 6 | } 7 | -------------------------------------------------------------------------------- /helpers/error.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func ErrorWithLog(err error) { 9 | if err != nil { 10 | log.Fatalf("Error while create configuration [%s]", err.Error()) 11 | os.Exit(1) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /common/code/error_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ErrorLoggerCode = `package helpers 4 | 5 | import ( 6 | "log" 7 | "os" 8 | ) 9 | 10 | func ErrorLogger(err error) { 11 | if err != nil { 12 | log.Fatalf("❌ error :%v \n", err) 13 | os.Exit(1) 14 | } 15 | } 16 | ` 17 | -------------------------------------------------------------------------------- /common/code/gen/settings.yaml: -------------------------------------------------------------------------------- 1 | database: 2 | driver: mysql 3 | host: localhost 4 | port: 3306 5 | username: user 6 | password: password 7 | name: database 8 | sslmode: disable 9 | max_idle_conn: 30 10 | max_open_conn: 20 11 | life_time_conn: 40 12 | -------------------------------------------------------------------------------- /common/code/gen/settings.toml: -------------------------------------------------------------------------------- 1 | 2 | [database] 3 | driver = "mysql" 4 | host = "localhost" 5 | life_time_conn = 40 6 | max_idle_conn = 30 7 | max_open_conn = 20 8 | name = "database" 9 | password = "password" 10 | port = 3306 11 | sslmode = "disable" 12 | username = "user" 13 | -------------------------------------------------------------------------------- /common/code/gen/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": { 3 | "driver": "mysql", 4 | "host": "localhost", 5 | "port": 3306, 6 | "username": "user", 7 | "password": "password", 8 | "name": "database", 9 | "sslmode": "disable", 10 | "max_idle_conn": 30, 11 | "max_open_conn": 20, 12 | "life_time_conn": 40 13 | } 14 | } -------------------------------------------------------------------------------- /helpers/version.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "os/exec" 5 | "regexp" 6 | ) 7 | 8 | func GetGoVersion() string { 9 | execRes, err := exec.Command("go", "version").Output() 10 | ErrorWithLog(err) 11 | 12 | getVer := regexp.MustCompile(`\d+\.\d+`) 13 | version := getVer.FindString(string(execRes)) 14 | 15 | return version 16 | } 17 | -------------------------------------------------------------------------------- /helpers/version_test.go: -------------------------------------------------------------------------------- 1 | package helpers_test 2 | 3 | import ( 4 | "regexp" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | 9 | "github.com/fanchann/go-starter/helpers" 10 | ) 11 | 12 | func TestGetGoVersion(t *testing.T) { 13 | goVer := helpers.GetGoVersion() 14 | expectedVersion, errNotMatch := regexp.MatchString("1.2*", goVer) 15 | 16 | assert.Nil(t, errNotMatch) 17 | assert.True(t, expectedVersion, "golang version not detected") 18 | 19 | } 20 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/fanchann/go-starter 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/manifoldco/promptui v0.9.0 7 | github.com/pelletier/go-toml v1.9.5 8 | github.com/stretchr/testify v1.8.4 9 | gopkg.in/yaml.v3 v3.0.1 10 | ) 11 | 12 | require ( 13 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect 14 | github.com/davecgh/go-spew v1.1.1 // indirect 15 | github.com/pmezard/go-difflib v1.0.0 // indirect 16 | github.com/stretchr/objx v0.5.0 // indirect 17 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b // indirect 18 | ) 19 | -------------------------------------------------------------------------------- /common/code/config_reader_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ViperConfiguration = `package config 4 | 5 | import "github.com/spf13/viper" 6 | 7 | func NewViper(in string) *viper.Viper { 8 | v := viper.New() 9 | 10 | switch in { 11 | case "prod": 12 | in = "config.prod" 13 | case "dev": 14 | in = "config.dev" 15 | default: 16 | in = "config.dev" 17 | } 18 | 19 | v.SetConfigName(in) 20 | v.SetConfigType("yaml") 21 | v.AddConfigPath("../") 22 | v.AddConfigPath("./") 23 | 24 | if err := v.ReadInConfig(); err != nil { 25 | panic(err) 26 | } 27 | 28 | return v 29 | }` 30 | -------------------------------------------------------------------------------- /helpers/yaml.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | import ( 4 | "fmt" 5 | "io/fs" 6 | "io/ioutil" 7 | "log" 8 | 9 | "gopkg.in/yaml.v3" 10 | ) 11 | 12 | type StarterConfigurationYamlVi struct { 13 | Version string `yaml:"version"` 14 | Package string `yaml:"package"` 15 | Database string `yaml:"database"` 16 | } 17 | 18 | func NewStarterYamlParser(file string) StarterConfigurationYamlVi { 19 | dataFile, err := ioutil.ReadFile(file) 20 | if err != nil { 21 | log.Fatalf("configuration starter.yaml not found!\n") 22 | } 23 | var starter StarterConfigurationYamlVi 24 | if err := yaml.Unmarshal(dataFile, &starter); err != nil { 25 | log.Fatalf("Error %v", err) 26 | } 27 | return starter 28 | 29 | } 30 | 31 | func NewYamlWriter(code map[string]interface{}, filePath, fileName string) error { 32 | codeByte, err := yaml.Marshal(code) 33 | if err != nil { 34 | return err 35 | } 36 | loc := fmt.Sprintf("%s/%s", filePath, fileName) 37 | 38 | if err := ioutil.WriteFile(loc, codeByte, fs.ModePerm|fs.ModeAppend); err != nil { 39 | return err 40 | } 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /common/code/compose_gen_test.go: -------------------------------------------------------------------------------- 1 | package code_test 2 | 3 | import ( 4 | "io/fs" 5 | "io/ioutil" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/assert" 9 | "gopkg.in/yaml.v3" 10 | 11 | "github.com/fanchann/go-starter/common/code" 12 | ) 13 | 14 | var ( 15 | genFolder = "./gen/" 16 | ) 17 | 18 | func TestGenMysqlCompose(t *testing.T) { 19 | m := code.ComposeCodeGenerate("mysql") 20 | out, err := yaml.Marshal(m) 21 | assert.Nil(t, err) 22 | 23 | err2 := ioutil.WriteFile(genFolder+"mysql.yaml", out, fs.ModePerm|fs.ModeAppend) 24 | assert.Nil(t, err2) 25 | } 26 | 27 | func TestGenPostgresCompose(t *testing.T) { 28 | m := code.ComposeCodeGenerate("postgres") 29 | out, err := yaml.Marshal(m) 30 | assert.Nil(t, err) 31 | 32 | err2 := ioutil.WriteFile(genFolder+"postgres.yaml", out, fs.ModePerm|fs.ModeAppend) 33 | assert.Nil(t, err2) 34 | } 35 | 36 | func TestGenMongoCompose(t *testing.T) { 37 | m := code.ComposeCodeGenerate("mongodb") 38 | out, err := yaml.Marshal(m) 39 | assert.Nil(t, err) 40 | 41 | err2 := ioutil.WriteFile(genFolder+"mongodb.yaml", out, fs.ModePerm|fs.ModeAppend) 42 | assert.Nil(t, err2) 43 | } 44 | -------------------------------------------------------------------------------- /common/code/config_code_test.go: -------------------------------------------------------------------------------- 1 | package code_test 2 | 3 | import ( 4 | "io/fs" 5 | "io/ioutil" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/assert" 9 | "gopkg.in/yaml.v3" 10 | 11 | "github.com/fanchann/go-starter/common/code" 12 | ) 13 | 14 | func TestGenConfigMysql(t *testing.T) { 15 | m := code.ConfigurationFileGenerate("mysql") 16 | 17 | out, err := yaml.Marshal(m) 18 | assert.Nil(t, err) 19 | 20 | err2 := ioutil.WriteFile(genFolder+"config.mysql.yaml", out, fs.ModePerm|fs.ModeAppend) 21 | assert.Nil(t, err2) 22 | } 23 | 24 | func TestGenConfigMongoDB(t *testing.T) { 25 | 26 | m := code.ConfigurationFileGenerate("mongodb") 27 | out, err := yaml.Marshal(m) 28 | assert.Nil(t, err) 29 | 30 | err2 := ioutil.WriteFile(genFolder+"config.mongodb.yaml", out, fs.ModePerm|fs.ModeAppend) 31 | assert.Nil(t, err2) 32 | } 33 | 34 | func TestGenConfigPostgres(t *testing.T) { 35 | m := code.ConfigurationFileGenerate("postgres") 36 | out, err := yaml.Marshal(m) 37 | assert.Nil(t, err) 38 | 39 | err2 := ioutil.WriteFile(genFolder+"config.postgres.yaml", out, fs.ModePerm|fs.ModeAppend) 40 | assert.Nil(t, err2) 41 | } 42 | -------------------------------------------------------------------------------- /common/code/config_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ( 4 | postgresYamlConfig = map[string]interface{}{ 5 | "database": map[string]interface{}{ 6 | "username": "postgres", 7 | "password": "postgres", 8 | "host": "localhost", 9 | "port": 5432, 10 | "name": "test", 11 | "sslmode": "disable", 12 | "time_zone": "Asia/Jakarta", 13 | }, 14 | } 15 | 16 | mysqlYamlConfig = map[string]interface{}{ 17 | "database": map[string]interface{}{ 18 | "username": "root", 19 | "password": "root", 20 | "host": "localhost", 21 | "port": 3306, 22 | "name": "information_schema", 23 | "pool": map[string]interface{}{ 24 | "idle": 15, 25 | "max": 30, 26 | "lifetime": 120, 27 | }, 28 | }, 29 | } 30 | 31 | mongoYamlConfig = map[string]interface{}{ 32 | "database": map[string]interface{}{ 33 | "url": "mongodb://localhost:27017", 34 | "name": "test", 35 | }, 36 | } 37 | ) 38 | 39 | func ConfigurationFileGenerate(using string) map[string]interface{} { 40 | switch using { 41 | case "mongodb": 42 | return mongoYamlConfig 43 | case "mysql": 44 | return mysqlYamlConfig 45 | case "postgres": 46 | return postgresYamlConfig 47 | default: 48 | return mysqlYamlConfig 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /common/functions/app_test.go: -------------------------------------------------------------------------------- 1 | package functions_test 2 | 3 | import ( 4 | "errors" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | "github.com/stretchr/testify/mock" 9 | 10 | functions_mocks "github.com/fanchann/go-starter/common/functions/mock" 11 | ) 12 | 13 | var ( 14 | funcMock = functions_mocks.IAppPathGenerator{mock.Mock{}} 15 | errorMsg = errors.New("failed generate structure") 16 | ) 17 | 18 | func TestCreatePathAppFailed(t *testing.T) { 19 | funcMock.Mock.On("CreateAppPath", "").Return(errorMsg) 20 | err := funcMock.CreateAppPath("") 21 | 22 | assert.EqualError(t, err, errorMsg.Error()) 23 | } 24 | 25 | func TestCreateAppSuccess(t *testing.T) { 26 | funcMock.Mock.On("CreateAppPath", "$HOME/app").Return(nil) 27 | err := funcMock.CreateAppPath("$HOME/app") 28 | 29 | assert.Nil(t, err) 30 | } 31 | 32 | func TestGenerateCodeSuccess(t *testing.T) { 33 | funcMock.Mock.On("GenerateAppCode", "HelloWorld").Return(nil) 34 | err := funcMock.GenerateAppCode("HelloWorld") 35 | 36 | assert.Nil(t, err) 37 | } 38 | 39 | func TestGenerateCodeFailed(t *testing.T) { 40 | funcMock.Mock.On("GenerateAppCode", "").Return(errorMsg) 41 | 42 | err := funcMock.GenerateAppCode("") 43 | 44 | assert.NotNil(t, err) 45 | assert.EqualError(t, err, errorMsg.Error()) 46 | } 47 | -------------------------------------------------------------------------------- /common/functions/app_impl.go: -------------------------------------------------------------------------------- 1 | package functions 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "path/filepath" 7 | "text/template" 8 | ) 9 | 10 | type AppPath struct { 11 | BasePath string 12 | } 13 | 14 | func (a *AppPath) CreateAppPath(path string) error { 15 | absPath := filepath.Join(a.BasePath, path) 16 | return os.MkdirAll(absPath, os.ModePerm) 17 | } 18 | 19 | func (a *AppPath) GenerateAppCode(code interface{}, path, fileName, goVer, pkg string) error { 20 | tpl, errParse := parseTemplate(code) 21 | if errParse != nil { 22 | return errParse 23 | } 24 | 25 | var tplBuf bytes.Buffer 26 | if errExecTemplate := executeTemplate(tpl, &tplBuf, goVer, pkg); errExecTemplate != nil { 27 | return errExecTemplate 28 | } 29 | 30 | absFilePath := filepath.Join(a.BasePath, path, fileName) 31 | return writeToFile(absFilePath, tplBuf.Bytes()) 32 | } 33 | 34 | func writeToFile(path string, code []byte) error { 35 | file, err := os.Create(path) 36 | if err != nil { 37 | return err 38 | } 39 | defer file.Close() 40 | 41 | _, err = file.Write(code) 42 | return err 43 | } 44 | 45 | func parseTemplate(code interface{}) (*template.Template, error) { 46 | return template.New("").Parse(code.(string)) 47 | } 48 | 49 | func executeTemplate(t *template.Template, tpl *bytes.Buffer, goVersion, pkgName string) error { 50 | data := struct { 51 | GoVersion string 52 | Package string 53 | }{ 54 | GoVersion: goVersion, 55 | Package: pkgName, 56 | } 57 | 58 | return t.Execute(tpl, data) 59 | } 60 | -------------------------------------------------------------------------------- /common/functions/mock/app_mocks.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.32.0. DO NOT EDIT. 2 | 3 | package functions_mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // IAppPathGenerator is an autogenerated mock type for the IAppPathGenerator type 8 | type IAppPathGenerator struct { 9 | mock.Mock 10 | } 11 | 12 | // CreateAppPath provides a mock function with given fields: path 13 | func (_m *IAppPathGenerator) CreateAppPath(path string) error { 14 | ret := _m.Called(path) 15 | 16 | var r0 error 17 | if rf, ok := ret.Get(0).(func(string) error); ok { 18 | r0 = rf(path) 19 | } else { 20 | r0 = ret.Error(0) 21 | } 22 | 23 | return r0 24 | } 25 | 26 | // GenerateAppCode provides a mock function with given fields: code 27 | func (_m *IAppPathGenerator) GenerateAppCode(code string) error { 28 | ret := _m.Called(code) 29 | 30 | var r0 error 31 | if rf, ok := ret.Get(0).(func(string) error); ok { 32 | r0 = rf(code) 33 | } else { 34 | r0 = ret.Error(0) 35 | } 36 | 37 | return r0 38 | } 39 | 40 | // NewIAppPathGenerator creates a new instance of IAppPathGenerator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 41 | // The first argument is typically a *testing.T value. 42 | func NewIAppPathGenerator(t interface { 43 | mock.TestingT 44 | Cleanup(func()) 45 | }) *IAppPathGenerator { 46 | mock := &IAppPathGenerator{} 47 | mock.Mock.Test(t) 48 | 49 | t.Cleanup(func() { mock.AssertExpectations(t) }) 50 | 51 | return mock 52 | } 53 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "log" 7 | "os" 8 | 9 | "github.com/fanchann/go-starter/app" 10 | "github.com/fanchann/go-starter/helpers" 11 | ) 12 | 13 | var ( 14 | logo = ` 15 | ┌─┐┌─┐ ┌─┐┌┬┐┌─┐┬─┐┌┬┐┌─┐┬─┐ 16 | │ ┬│ │───└─┐ │ ├─┤├┬┘ │ ├┤ ├┬┘ 17 | └─┘└─┘ └─┘ ┴ ┴ ┴┴└─ ┴ └─┘┴└─ 18 | ` 19 | showHelp = flag.Bool("help", false, "show help message") 20 | starterFile = flag.String("f", "starter.yaml", "starter configuration file") 21 | 22 | starterDefaultConfiguration = map[string]interface{}{ 23 | "version": "1", 24 | "package": "your-name-package", 25 | "database": "mysql", 26 | } 27 | ) 28 | 29 | func init() { 30 | flag.Parse() 31 | } 32 | 33 | func main() { 34 | fmt.Printf("%v \n", logo) 35 | newArgs := os.Args[1:] 36 | 37 | if len(newArgs) > 0 { 38 | command := newArgs[0] 39 | switch command { 40 | case "new": 41 | log.Print("Success generate starter.yaml \n") 42 | generateConfiguration() 43 | return 44 | case "help": 45 | printHelpMessage() 46 | return 47 | } 48 | } 49 | 50 | processStarterApp(starterFile) 51 | 52 | } 53 | 54 | func generateConfiguration() error { 55 | return helpers.NewYamlWriter(starterDefaultConfiguration, ".", "starter.yaml") 56 | } 57 | 58 | func processStarterApp(appConfigFile *string) { 59 | starterConfiguration := helpers.NewStarterYamlParser(*appConfigFile) 60 | err := app.GoStarter(app.Options{AppName: starterConfiguration.Package, Driver: starterConfiguration.Database}) 61 | helpers.ErrorWithLog(err) 62 | } 63 | 64 | func printHelpMessage() { 65 | fmt.Println("Usage: go-starter [OPTIONS]") 66 | fmt.Println("\nOptions:") 67 | flag.PrintDefaults() 68 | fmt.Println("\nExamples:") 69 | fmt.Println(" go-starter new Generate configuration file") 70 | fmt.Println(" go-starter Run the application") 71 | fmt.Println(" go-starter -f=configuration.yaml [default: starter.yaml] Specify a custom configuration file") 72 | } 73 | -------------------------------------------------------------------------------- /common/code/main_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ( 4 | MysqlMain = `package main 5 | 6 | import ( 7 | "flag" 8 | "fmt" 9 | 10 | "{{.Package}}/internals/config" 11 | "{{.Package}}/internals/helpers" 12 | ) 13 | 14 | var stage *string 15 | 16 | func init() { 17 | stage = flag.String("s", "dev", "❌ please input stage !") 18 | flag.Parse() 19 | } 20 | 21 | func main() { 22 | v := config.NewViper(*stage) 23 | db := config.NewMysqlConnection(v) 24 | 25 | d, err := db.DB() 26 | helpers.ErrorLogger(err) 27 | 28 | err2 := d.Ping() 29 | helpers.ErrorLogger(err2) 30 | 31 | fmt.Println("✅ connected") 32 | } 33 | ` 34 | 35 | PostgresMain = `package main 36 | 37 | import ( 38 | "{{.Package}}/internals/config" 39 | "{{.Package}}/internals/helpers" 40 | "flag" 41 | "fmt" 42 | ) 43 | 44 | var stage *string 45 | 46 | func init() { 47 | stage = flag.String("s", "dev", "❌ please input stage !") 48 | flag.Parse() 49 | } 50 | 51 | func main() { 52 | v := config.NewViper(*stage) 53 | db := config.NewPostgresConnection(v) 54 | 55 | d, err := db.DB() 56 | helpers.ErrorLogger(err) 57 | 58 | err2 := d.Ping() 59 | helpers.ErrorLogger(err2) 60 | 61 | fmt.Println("✅ connected") 62 | } 63 | ` 64 | 65 | MongoMain = `package main 66 | 67 | import ( 68 | "{{.Package}}/internals/config" 69 | "{{.Package}}/internals/helpers" 70 | "context" 71 | "flag" 72 | "fmt" 73 | "time" 74 | 75 | "go.mongodb.org/mongo-driver/mongo/readpref" 76 | ) 77 | 78 | var stage *string 79 | 80 | func init() { 81 | stage = flag.String("s", "dev", "❌ please input stage !") 82 | flag.Parse() 83 | } 84 | 85 | func main() { 86 | v := config.NewViper(*stage) 87 | db := config.NewMongoConnection(v) 88 | 89 | 90 | ctx, errTimeout := context.WithTimeout(context.Background(), time.Second*5) 91 | defer errTimeout() 92 | 93 | err := db.Client().Ping(ctx, &readpref.ReadPref{}) 94 | helpers.ErrorLogger(err) 95 | 96 | fmt.Println("✅ connected") 97 | } 98 | ` 99 | ) 100 | -------------------------------------------------------------------------------- /common/code/compose_gen.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ( 4 | mysqlCompose = map[string]interface{}{ 5 | "version": "3.8", 6 | "services": map[string]interface{}{ 7 | "mysql_db": map[string]interface{}{ 8 | "image": "mysql:latest", 9 | "container_name": "mysql_db", 10 | "restart": "on-failure", 11 | "ports": []interface{}{ 12 | "3306:3306", 13 | }, 14 | "environment": []string{ 15 | "MYSQL_ROOT_PASSWORD=root", 16 | }, 17 | "command": []string{ 18 | "mysqld", 19 | "--character-set-server=utf8mb4", 20 | "--collation-server=utf8mb4_unicode_ci", 21 | "--default-time-zone=+09:00", 22 | }, 23 | "networks": []string{ 24 | "mysql_network", 25 | }, 26 | }, 27 | }, 28 | "networks": map[string]interface{}{ 29 | "mysql_network": map[string]interface{}{ 30 | "driver": "bridge", 31 | "name": "mysql_network", 32 | }, 33 | }, 34 | } 35 | postgresCompose = map[string]interface{}{ 36 | "version": "3.8", 37 | "services": map[string]interface{}{ 38 | "postgres": map[string]interface{}{ 39 | "image": "postgres:latest", 40 | "restart": "always", 41 | "environment": []string{ 42 | "POSTGRES_USER=postgres", 43 | "POSTGRES_PASSWORD=postgres", 44 | "POSTGRES_DB=test", 45 | }, 46 | "logging": map[string]interface{}{ 47 | "options": map[string]interface{}{ 48 | "max-size": "10m", 49 | "max-file": "3", 50 | }, 51 | }, 52 | "ports": []string{"5432:5432"}, 53 | }, 54 | }, 55 | } 56 | mongoCompose = map[string]interface{}{ 57 | "version": "3.8", 58 | "services": map[string]interface{}{ 59 | "mongodb": map[string]interface{}{ 60 | "image": "mongo:4.4.2-bionic", 61 | "container_name": "mongodb", 62 | "ports": []string{"27017:27017"}, 63 | "environment": []string{ 64 | "MONGO_INITDB_DATABASE=test", 65 | "MONGO_INITDB_ROOT_USERNAME=admin", 66 | "MONGO_INITDB_ROOT_PASSWORD=admin", 67 | }, 68 | "networks": []string{"mongo_net"}, 69 | }, 70 | }, 71 | "networks": map[string]interface{}{ 72 | "mongo_net": map[string]interface{}{ 73 | "driver": "bridge", 74 | }, 75 | }, 76 | } 77 | ) 78 | 79 | func ComposeCodeGenerate(driver string) map[string]interface{} { 80 | switch driver { 81 | case "mysql": 82 | return mysqlCompose 83 | case "postgres": 84 | return postgresCompose 85 | case "mongodb": 86 | return mongoCompose 87 | default: 88 | return mysqlCompose 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/app.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fanchann/go-starter/common/code" 7 | "github.com/fanchann/go-starter/common/functions" 8 | "github.com/fanchann/go-starter/helpers" 9 | ) 10 | 11 | type Options struct { 12 | AppName string 13 | Driver string 14 | } 15 | 16 | type AppStructure struct { 17 | Path string 18 | Code interface{} 19 | FileName string 20 | } 21 | 22 | func GoStarter(opt Options) error { 23 | // basePath := strings.ReplaceAll(opt.AppName, "/", "-") 24 | restDirectoryList := []string{ 25 | "cmd", 26 | "api", 27 | "db/migrations", 28 | "internals/config", 29 | "internals/delivery/http", 30 | "internals/delivery/messaging", 31 | "internals/gateway", 32 | "internals/models", 33 | "internals/repository", 34 | "internals/usecase", 35 | "internals/helpers", 36 | "tests", 37 | } 38 | return generateStructure(opt, restDirectoryList) 39 | } 40 | 41 | func generateStructure(opt Options, DirectoryList []string) error { 42 | basePath := "./" 43 | home := functions.AppPath{BasePath: basePath} 44 | for _, dir := range DirectoryList { 45 | err := home.CreateAppPath(dir) 46 | if err != nil { 47 | return fmt.Errorf("failed to create layer '%s': [%v]", dir, err) 48 | } else { 49 | fmt.Printf("layer '%s' created successfully.\n", dir) 50 | } 51 | } 52 | 53 | structures := []AppStructure{ 54 | {Path: "cmd/", Code: code.NewDatabaseOptions(opt.Driver).MainApp, FileName: "main.go"}, 55 | {Path: basePath, Code: code.NewDatabaseOptions(opt.Driver).Dependencies, FileName: "go.mod"}, 56 | {Path: "internals/config/", Code: code.NewDatabaseOptions(opt.Driver).DatabaseDriver, FileName: fmt.Sprintf("%s.go", opt.Driver)}, 57 | {Path: "internals/config/", Code: code.ViperConfiguration, FileName: "viper.go"}, 58 | {Path: "internals/helpers/", Code: code.ErrorLoggerCode, FileName: "error.go"}, 59 | } 60 | 61 | // code generator 62 | for _, structure := range structures { 63 | if errGenCode := home.GenerateAppCode(structure.Code, structure.Path, structure.FileName, helpers.GetGoVersion(), opt.AppName); errGenCode != nil { 64 | return errGenCode 65 | } 66 | } 67 | 68 | // config generator 69 | config := []AppStructure{ 70 | {Path: basePath, Code: code.NewDatabaseOptions(opt.Driver).ConfigurationFile, FileName: "config.dev.yaml"}, 71 | {Path: basePath, Code: code.NewDatabaseOptions(opt.Driver).DockerCompose, FileName: "docker-compose.yaml"}, 72 | } 73 | 74 | for _, cfgGen := range config { 75 | if errGenConfig := helpers.NewYamlWriter(cfgGen.Code.(map[string]interface{}), cfgGen.Path, cfgGen.FileName); errGenConfig != nil { 76 | return errGenConfig 77 | } 78 | } 79 | return nil 80 | } 81 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= 2 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 3 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= 4 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 5 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= 6 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 9 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= 11 | github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= 12 | github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= 13 | github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= 14 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 15 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 16 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 17 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 18 | github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= 19 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 20 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 21 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 22 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 23 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 24 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4= 25 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 26 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 27 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 28 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 29 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 30 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Go-Starter 2 | ![App Screenshot](/assets/GO-STARTER.png) 3 | 4 | ## What is Go-Starter? 5 | This tool helps you to do the tedious work of setting configuration and creating layers for the REST API 6 | 7 | ## go-starter command 8 | ```sh 9 | go-starter help 10 | 11 | ┌─┐┌─┐ ┌─┐┌┬┐┌─┐┬─┐┌┬┐┌─┐┬─┐ 12 | │ ┬│ │───└─┐ │ ├─┤├┬┘ │ ├┤ ├┬┘ 13 | └─┘└─┘ └─┘ ┴ ┴ ┴┴└─ ┴ └─┘┴└─ 14 | 15 | Usage: go-starter [OPTIONS] 16 | 17 | Options: 18 | -f string 19 | starter configuration file (default "starter.yaml") 20 | help 21 | show help message 22 | 23 | Examples: 24 | go-starter new Generate configuration file 25 | go-starter Run the application 26 | go-starter -f=configuration.yaml[default: starter.yaml] Specify a custom configuration file 27 | ``` 28 | ## generate starter configuration 29 | ```sh 30 | go-starter new 31 | 32 | ┌─┐┌─┐ ┌─┐┌┬┐┌─┐┬─┐┌┬┐┌─┐┬─┐ 33 | │ ┬│ │───└─┐ │ ├─┤├┬┘ │ ├┤ ├┬┘ 34 | └─┘└─┘ └─┘ ┴ ┴ ┴┴└─ ┴ └─┘┴└─ 35 | 36 | 2024/01/18 16:46:54 Success generate starter.yaml 37 | ``` 38 | 39 | `starter.yaml` is a go-starter configuration: 40 | ```yaml 41 | version: "1" 42 | package: your-name-app 43 | database: database 44 | ``` 45 | database support : 46 | - mysql 47 | - mongodb 48 | - postgres 49 | 50 | ## generate structure project 51 | ```sh 52 | go-starter 53 | 54 | ┌─┐┌─┐ ┌─┐┌┬┐┌─┐┬─┐┌┬┐┌─┐┬─┐ 55 | │ ┬│ │───└─┐ │ ├─┤├┬┘ │ ├┤ ├┬┘ 56 | └─┘└─┘ └─┘ ┴ ┴ ┴┴└─ ┴ └─┘┴└─ 57 | 58 | layer 'cmd' created successfully. 59 | layer 'api' created successfully. 60 | layer 'db/migrations' created successfully. 61 | layer 'internals/config' created successfully. 62 | layer 'internals/delivery/http' created successfully. 63 | layer 'internals/delivery/messaging' created successfully. 64 | layer 'internals/gateway' created successfully. 65 | layer 'internals/models' created successfully. 66 | layer 'internals/repository' created successfully. 67 | layer 'internals/usecase' created successfully. 68 | layer 'internals/helpers' created successfully. 69 | layer 'tests' created successfully. 70 | ``` 71 | 72 | ## Structure 73 | Structure reference 74 | - [Golang standards project layout](https://github.com/golang-standards/project-layout/) 75 | ```sh 76 | ├── api 77 | ├── cmd 78 | │   └── main.go 79 | ├── config.dev.yaml 80 | ├── db 81 | │   └── migrations 82 | ├── docker-compose.yaml 83 | ├── go.mod 84 | ├── internals 85 | │   ├── config 86 | │   │   ├── mysql.go ## filename following the database 87 | │   │   └── viper.go 88 | │   ├── delivery 89 | │   │   ├── http 90 | │   │   └── messaging 91 | │   ├── gateway 92 | │   ├── helpers 93 | │   │   └── error.go 94 | │   ├── models 95 | │   ├── repository 96 | │   └── usecase 97 | ├── starter.yaml 98 | └── tests 99 | 100 | ``` 101 | 102 | ## About go-starter 103 | This tool adopt \ 104 | [gorm](https://gorm.io/)\ 105 | [mongo client](https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo)\ 106 | [viper](https://pkg.go.dev/github.com/dvln/viper) 107 | 108 | Database support: 109 | | Database | Support | 110 | | :---------------- | :------: | 111 | | MySQL | ✅ | 112 | | PostgreSQL | ✅ | 113 | | MongoDB | ✅ | 114 | 115 | ## Installation 116 | ```sh 117 | go install github.com/fanchann/go-starter@latest 118 | ``` 119 | 120 | see older version here [version](https://github.com/fanchann/go-starter/tags) 121 | 122 | ## Running Your App 123 | After generating the template, enter the folder that has been generated by `go-starter`, and then add dependencies using the following command. 124 | ```sh 125 | go mod tidy 126 | ``` 127 | This command will download and install the required dependencies for your project\ 128 | After success install dependencies, run app with command : 129 | ```sh 130 | go run cmd/main.go 131 | ``` 132 | ## Authors 133 | 134 | - [@fanchann](https://github.com/fanchann) 135 | 136 | -------------------------------------------------------------------------------- /common/code/db_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | type AppConfiguration struct { 4 | Dependencies string 5 | DatabaseDriver string 6 | ConfigurationFile map[string]interface{} 7 | DockerCompose map[string]interface{} 8 | MainApp string 9 | } 10 | 11 | var MysqlDBConfig = `package config 12 | 13 | import ( 14 | "fmt" 15 | "time" 16 | 17 | "{{.Package}}/internals/helpers" 18 | "github.com/spf13/viper" 19 | "gorm.io/driver/mysql" 20 | "gorm.io/gorm" 21 | ) 22 | 23 | func NewMysqlConnection(v *viper.Viper) *gorm.DB { 24 | username := v.GetString("database.username") 25 | password := v.GetString("database.password") 26 | host := v.GetString("database.host") 27 | port := v.GetInt("database.port") 28 | database := v.GetString("database.name") 29 | idleConnection := v.GetInt("database.pool.idle") 30 | maxConnection := v.GetInt("database.pool.max") 31 | maxLifeTimeConnection := v.GetInt("database.pool.lifetime") 32 | 33 | dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", username, password, host, port, database) 34 | 35 | db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) 36 | helpers.ErrorLogger(err) 37 | 38 | connection, err := db.DB() 39 | helpers.ErrorLogger(err) 40 | 41 | connection.SetMaxIdleConns(idleConnection) 42 | connection.SetMaxOpenConns(maxConnection) 43 | connection.SetConnMaxLifetime(time.Second * time.Duration(maxLifeTimeConnection)) 44 | 45 | return db 46 | } 47 | ` 48 | 49 | var PostgresDBConfig = `package config 50 | 51 | import ( 52 | "{{.Package}}/internals/helpers" 53 | "fmt" 54 | 55 | "github.com/spf13/viper" 56 | "gorm.io/driver/postgres" 57 | "gorm.io/gorm" 58 | ) 59 | 60 | func NewPostgresConnection(v *viper.Viper) *gorm.DB { 61 | username := v.GetString("database.username") 62 | password := v.GetString("database.password") 63 | host := v.GetString("database.host") 64 | port := v.GetInt("database.port") 65 | database := v.GetString("database.name") 66 | sslMode := v.GetString("database.sslmode") 67 | timeZone := v.GetString("database.time_zone") 68 | 69 | dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", host, username, password, database, port, sslMode, timeZone) 70 | db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) 71 | helpers.ErrorLogger(err) 72 | 73 | return db 74 | } 75 | ` 76 | 77 | var MongoDBConfig = `package config 78 | 79 | import ( 80 | "{{.Package}}/internals/helpers" 81 | "context" 82 | 83 | "github.com/spf13/viper" 84 | "go.mongodb.org/mongo-driver/mongo" 85 | "go.mongodb.org/mongo-driver/mongo/options" 86 | ) 87 | 88 | func NewMongoConnection(v *viper.Viper) *mongo.Database { 89 | ctx := context.Background() 90 | 91 | url := v.GetString("database.url") 92 | clientOptions := options.Client() 93 | clientOptions.ApplyURI(url) 94 | client, err := mongo.NewClient(clientOptions) 95 | if err != nil { 96 | helpers.ErrorLogger(err) 97 | 98 | } 99 | 100 | err = client.Connect(ctx) 101 | if err != nil { 102 | helpers.ErrorLogger(err) 103 | } 104 | 105 | return client.Database(v.GetString("database.name")) 106 | } 107 | ` 108 | 109 | func NewDatabaseOptions(driver string) *AppConfiguration { 110 | switch driver { 111 | case "mongodb": 112 | return &AppConfiguration{ 113 | Dependencies: MongoDBDependencies, 114 | DatabaseDriver: MongoDBConfig, 115 | DockerCompose: ComposeCodeGenerate(driver), 116 | MainApp: MongoMain, 117 | ConfigurationFile: ConfigurationFileGenerate(driver), 118 | } 119 | case "mysql": 120 | return &AppConfiguration{ 121 | Dependencies: MysqlDependencies, 122 | DatabaseDriver: MysqlDBConfig, 123 | DockerCompose: ComposeCodeGenerate(driver), 124 | MainApp: MysqlMain, 125 | ConfigurationFile: ConfigurationFileGenerate(driver), 126 | } 127 | case "postgres": 128 | return &AppConfiguration{ 129 | Dependencies: PostgresDependencies, 130 | DatabaseDriver: PostgresDBConfig, 131 | DockerCompose: ComposeCodeGenerate(driver), 132 | MainApp: PostgresMain, 133 | ConfigurationFile: ConfigurationFileGenerate(driver), 134 | } 135 | default: 136 | return &AppConfiguration{ 137 | Dependencies: MysqlDependencies, 138 | DatabaseDriver: MysqlDBConfig, 139 | DockerCompose: ComposeCodeGenerate(driver), 140 | MainApp: MysqlMain, 141 | ConfigurationFile: ConfigurationFileGenerate(driver), 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /common/code/dependencies_code.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | var ( 4 | MongoDBDependencies = `module {{.Package}} 5 | 6 | go {{.GoVersion}} 7 | 8 | require ( 9 | github.com/spf13/viper v1.18.2 10 | go.mongodb.org/mongo-driver v1.13.1 11 | ) 12 | 13 | require ( 14 | github.com/fsnotify/fsnotify v1.7.0 // indirect 15 | github.com/golang/snappy v0.0.1 // indirect 16 | github.com/hashicorp/hcl v1.0.0 // indirect 17 | github.com/klauspost/compress v1.17.0 // indirect 18 | github.com/magiconair/properties v1.8.7 // indirect 19 | github.com/mitchellh/mapstructure v1.5.0 // indirect 20 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect 21 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 22 | github.com/sagikazarmark/locafero v0.4.0 // indirect 23 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 24 | github.com/sourcegraph/conc v0.3.0 // indirect 25 | github.com/spf13/afero v1.11.0 // indirect 26 | github.com/spf13/cast v1.6.0 // indirect 27 | github.com/spf13/pflag v1.0.5 // indirect 28 | github.com/subosito/gotenv v1.6.0 // indirect 29 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect 30 | github.com/xdg-go/scram v1.1.2 // indirect 31 | github.com/xdg-go/stringprep v1.0.4 // indirect 32 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect 33 | go.uber.org/atomic v1.9.0 // indirect 34 | go.uber.org/multierr v1.9.0 // indirect 35 | golang.org/x/crypto v0.16.0 // indirect 36 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 37 | golang.org/x/sync v0.5.0 // indirect 38 | golang.org/x/sys v0.15.0 // indirect 39 | golang.org/x/text v0.14.0 // indirect 40 | gopkg.in/ini.v1 v1.67.0 // indirect 41 | gopkg.in/yaml.v3 v3.0.1 // indirect 42 | ) 43 | ` 44 | PostgresDependencies = `module {{.Package}} 45 | 46 | go {{.GoVersion}} 47 | 48 | require ( 49 | github.com/spf13/viper v1.18.2 50 | gorm.io/gorm v1.25.5 51 | ) 52 | 53 | require ( 54 | github.com/fsnotify/fsnotify v1.7.0 // indirect 55 | github.com/hashicorp/hcl v1.0.0 // indirect 56 | github.com/jackc/pgpassfile v1.0.0 // indirect 57 | github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect 58 | github.com/jackc/pgx/v5 v5.4.3 // indirect 59 | github.com/jinzhu/inflection v1.0.0 // indirect 60 | github.com/jinzhu/now v1.1.5 // indirect 61 | github.com/magiconair/properties v1.8.7 // indirect 62 | github.com/mitchellh/mapstructure v1.5.0 // indirect 63 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 64 | github.com/sagikazarmark/locafero v0.4.0 // indirect 65 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 66 | github.com/sourcegraph/conc v0.3.0 // indirect 67 | github.com/spf13/afero v1.11.0 // indirect 68 | github.com/spf13/cast v1.6.0 // indirect 69 | github.com/spf13/pflag v1.0.5 // indirect 70 | github.com/subosito/gotenv v1.6.0 // indirect 71 | go.uber.org/atomic v1.9.0 // indirect 72 | go.uber.org/multierr v1.9.0 // indirect 73 | golang.org/x/crypto v0.16.0 // indirect 74 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 75 | golang.org/x/sys v0.15.0 // indirect 76 | golang.org/x/text v0.14.0 // indirect 77 | gopkg.in/ini.v1 v1.67.0 // indirect 78 | gopkg.in/yaml.v3 v3.0.1 // indirect 79 | gorm.io/driver/postgres v1.5.4 // indirect 80 | ) 81 | ` 82 | 83 | MysqlDependencies = `module {{.Package}} 84 | 85 | go {{.GoVersion}} 86 | 87 | require ( 88 | github.com/spf13/viper v1.18.2 89 | gorm.io/driver/mysql v1.5.2 90 | gorm.io/gorm v1.25.5 91 | ) 92 | 93 | require ( 94 | github.com/fsnotify/fsnotify v1.7.0 // indirect 95 | github.com/go-sql-driver/mysql v1.7.0 // indirect 96 | github.com/hashicorp/hcl v1.0.0 // indirect 97 | github.com/jinzhu/inflection v1.0.0 // indirect 98 | github.com/jinzhu/now v1.1.5 // indirect 99 | github.com/magiconair/properties v1.8.7 // indirect 100 | github.com/mitchellh/mapstructure v1.5.0 // indirect 101 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 102 | github.com/sagikazarmark/locafero v0.4.0 // indirect 103 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 104 | github.com/sourcegraph/conc v0.3.0 // indirect 105 | github.com/spf13/afero v1.11.0 // indirect 106 | github.com/spf13/cast v1.6.0 // indirect 107 | github.com/spf13/pflag v1.0.5 // indirect 108 | github.com/subosito/gotenv v1.6.0 // indirect 109 | go.uber.org/atomic v1.9.0 // indirect 110 | go.uber.org/multierr v1.9.0 // indirect 111 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 112 | golang.org/x/sys v0.15.0 // indirect 113 | golang.org/x/text v0.14.0 // indirect 114 | gopkg.in/ini.v1 v1.67.0 // indirect 115 | gopkg.in/yaml.v3 v3.0.1 // indirect 116 | ) 117 | ` 118 | ) 119 | 120 | --------------------------------------------------------------------------------