wikingo/server/server.go

57 lines
1003 B
Go
Raw Normal View History

2022-03-15 21:50:11 +01:00
package server
import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/oscarmlage/wikingo/model"
"log"
"net/http"
)
2022-03-18 13:15:55 +01:00
// Depending on config we should open one store or other (Gorm, File,
// Git...)
var (
store model.StoreGorm
)
2022-03-15 21:50:11 +01:00
func Serve() {
2022-03-18 13:15:55 +01:00
// Store instance
2022-03-15 21:50:11 +01:00
err := store.Open()
if err != nil {
log.Panicln(err)
}
2022-03-18 13:15:55 +01:00
// Echo instance
2022-03-15 21:50:11 +01:00
e := echo.New()
2022-03-18 13:15:55 +01:00
// Routes
2022-03-15 21:50:11 +01:00
e.GET("/", WikiHome)
2022-03-18 13:15:55 +01:00
e.GET("/list", WikiListPages)
2022-03-15 21:50:11 +01:00
e.GET("/about", WikiAbout)
e.GET("/about/:id", WikiAbout)
2022-03-18 13:15:55 +01:00
// Logger
2022-03-15 21:50:11 +01:00
e.Logger.Fatal(e.Start(":2323"))
}
func WikiHome(c echo.Context) error {
res := store.GetPage()
fmt.Println(res)
return c.String(http.StatusOK, "WikiHome")
}
func WikiAbout(c echo.Context) error {
id := c.Param("id")
return c.String(http.StatusOK, "About the wiki. id:"+id)
}
2022-03-18 13:15:55 +01:00
func WikiListPages(c echo.Context) error {
fmt.Println("WikiListPages")
res, err := store.GetAllPages()
if err != nil {
log.Panicln(err)
}
fmt.Println(res)
return c.String(http.StatusOK, "WikiListPages")
}