-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 1.03 KB
/
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
38
package main
import (
"net/http"
_ "github.com/lib/pq"
"github.com/artamananda/artanymous/config"
"github.com/artamananda/artanymous/controller"
"github.com/artamananda/artanymous/helper"
"github.com/artamananda/artanymous/repository"
"github.com/artamananda/artanymous/service"
"github.com/go-playground/validator/v10"
"github.com/julienschmidt/httprouter"
)
func main() {
db := config.NewDB()
validate := validator.New()
messageRepository := repository.NewMessageRepository()
messageService := service.NewMessageService(messageRepository, db, validate)
messageController := controller.NewMessageController(messageService)
router := httprouter.New()
router.GET("/api/messages", messageController.FindAll)
router.GET("/api/messages/:messageId", messageController.FindById)
router.POST("/api/messages", messageController.Create)
router.DELETE("/api/messages/:messageId", messageController.Delete)
server := http.Server{
Addr: "localhost:3000",
Handler: router,
}
err := server.ListenAndServe()
helper.PanicIfError(err)
}