-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
32 lines (26 loc) · 924 Bytes
/
server.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/renatospaka/golang-rest-api/controller"
"github.com/renatospaka/golang-rest-api/repository"
"github.com/renatospaka/golang-rest-api/router"
"github.com/renatospaka/golang-rest-api/service"
)
var (
postRepository repository.PostRepository = repository.NewFirestorePostRepository()
postService service.PostService = service.NewPostService(postRepository)
postController controller.PostController = controller.NewPostController(postService)
httpRouter router.Router = router.NewChiRouter()
)
func main() {
const port = ":8000"
httpRouter.GET("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("Up and Running on port %s", port)
fmt.Fprintln(w, "Up and Running on port ", port)
})
httpRouter.GET("/posts", postController.GetPosts)
httpRouter.POST("/posts", postController.AddPosts)
httpRouter.SERVE(port)
}