Last active
December 18, 2020 13:50
-
-
Save Phalacrocorax/ffe5610ce8a95a9f106c031dfe0aee07 to your computer and use it in GitHub Desktop.
Go Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"{project}/models" | |
"{project}/routers" | |
) | |
func main() { | |
router := routers.InitRouter() | |
// Connect to database | |
models.ConnectDatabase() | |
// s := &http.Server{ | |
// Addr: fmt.Sprintf(":%d", setting.HTTPPort), | |
// Handler: router, | |
// ReadTimeout: setting.ReadTimeout, | |
// WriteTimeout: setting.WriteTimeout, | |
// MaxHeaderBytes: 1 << 20, | |
// } | |
// s.ListenAndServe() | |
router.Run(":5000") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import ( | |
"gorm.io/driver/postgres" | |
"gorm.io/gorm" | |
) | |
// DB instance | |
var DB *gorm.DB | |
// ConnectDatabase cadasomment | |
func ConnectDatabase() { | |
// https://github.com/jackc/pgx | |
dsn := "user={db_user} password={db_pass} DB.name={db_name} port=5432 sslmode=disable TimeZone=Asia/Tokyo" | |
database, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) | |
if err != nil { | |
panic("Failed to connect to database!") | |
} | |
// database.AutoMigrate(&Model{}) | |
DB = database | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://gist.githubusercontent.com/Phalacrocorax/ffe5610ce8a95a9f106c031dfe0aee07/raw/fe662596996e5a9df721f06ef21ed9e1d5be5739/main.go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment