-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 863 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"database/sql"
"log"
httpHandler "RESTExample/handler"
_ "github.com/go-sql-driver/mysql" //import for side effect
"github.com/labstack/echo/v4"
)
func main() {
dbHost := "localhost"
dbPort := "3306"
dbUser := "root"
dbPass := ""
dbName := "article"
dsn := dbUser + `:` + dbPass + `@tcp(` + dbHost + `:` + dbPort + `)/` + dbName + `?parseTime=1&loc=Asia%2FJakarta`
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
handler := httpHandler.InitArticle(db)
echoServer := echo.New()
// Register the handler
echoServer.GET("/articles", handler.FetchArticles)
echoServer.POST("/articles", handler.Insert)
echoServer.GET("/articles/:id", handler.Get)
echoServer.DELETE("/articles/:id", handler.Delete)
echoServer.PUT("/articles/:id", handler.Update)
// Start the server
echoServer.Start(":9090")
}