r_connection.NotifyClose(rabbitCloseError)
rabbitConn = connectToRabbitMQ(uri)
rabbitCloseError = make(chan *amqp.Error) // <---- look here
rabbitConn.NotifyClose(rabbitCloseError)
// exit program on ps kill and Ctrl+C...
exitc := make(chan os.Signal, 1)
signal.Notify(exitc, os.Interrupt, os.Kill, syscall.SIGTERM)
// some code or goroutines
// ...
sig := <- exitc
// some cleanup or signal logging and printing
var db *sql.DB
func connectDB() {
var err error
db, err = sql.Open("mysql", "root@/dbname")
}
var db *sql.DB
func connectDB() error {
var err error
if db, err = sql.Open("mysql", "root@/dbname"); err != nil {
return err
}
var db *sql.DB
func connectDB() (err error) {
db, err = sql.Open("mysql", "root@/dbname")
return
}
func main() {
http.HandleFunc("/", func(response http.ResponseWriter, request *http.Request) {
http.ServeFile(response, request, "/var/www/default/htdocs/index.html")
})
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("/var/www/default/htdocs/public"))))
http.HandleFunc("/json", func(response http.ResponseWriter, request *http.Request) {
// serves a JSON response
})
http.HandleFunc("/socket", func(w http.ResponseWriter, r *http.Request) {
// replies to the WebSocket
})
http.ListenAndServe(":3000", nil)
}
todo := MyList{Id:8888, Name: "Новое имя", IsTrue:false}
- Column name is the snake case of field's name
- Use ID field as primary key
Gorm provide a default model struct, you could embed it in your structtype Model struct { ID uint `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time } type User struct { gorm.Model Name string }