v1.0.0: import: import code from accounts
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
40c43c6726
commit
7f7fd9395c
8 changed files with 369 additions and 0 deletions
64
cmd/main.go
Normal file
64
cmd/main.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"gitlab.g3e.fr/h6n/users/lib"
|
||||
|
||||
"database/sql"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
var db *sql.DB = nil
|
||||
|
||||
func logout(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func isLoggedIn(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func init_database() {
|
||||
var err error = nil
|
||||
|
||||
connStr := "postgres://acc:totor@postgres:5432/accounts?sslmode=disable"
|
||||
|
||||
db, err = sql.Open("postgres", connStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func skip_auth(c echo.Context) bool {
|
||||
if c.Request().Method == "POST" && c.Path() == "/" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func main() {
|
||||
init_database()
|
||||
if err := lib.InitLoginBiscuit(); err != nil {
|
||||
return
|
||||
}
|
||||
e := echo.New()
|
||||
|
||||
// Middleware
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.Recover())
|
||||
e.Use(middleware.CORS())
|
||||
e.Use(lib.AuthMiddleware(skip_auth))
|
||||
|
||||
// Routes
|
||||
e.GET("/", isLoggedIn)
|
||||
e.POST("/", login)
|
||||
e.DELETE("/", logout)
|
||||
|
||||
// Start server
|
||||
e.Logger.Fatal(e.Start(":1222"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue