You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
3 months ago
|
package routes
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
"zestack.dev/env"
|
||
|
|
||
|
"github.com/gorilla/sessions"
|
||
|
"github.com/gorilla/websocket"
|
||
|
"github.com/wader/gormstore/v2"
|
||
|
"gorm.io/gorm"
|
||
|
"zestack.dev/slim"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
newline = []byte{'\n'}
|
||
|
space = []byte{' '}
|
||
|
|
||
|
upgrader *websocket.Upgrader
|
||
|
clients *sync.Map
|
||
|
broadcast chan []byte
|
||
|
|
||
|
store sessions.Store
|
||
|
db *gorm.DB
|
||
|
)
|
||
|
|
||
|
func Init(gdb *gorm.DB, s *slim.Slim) error {
|
||
|
db = gdb
|
||
|
upgrader = &websocket.Upgrader{}
|
||
|
clients = new(sync.Map)
|
||
|
broadcast = make(chan []byte)
|
||
|
store = gormstore.NewOptions(db, gormstore.Options{
|
||
|
TableName: env.String("DB_TABLE_PREFIX", "do_") + "sessions",
|
||
|
}, []byte("secret"))
|
||
|
|
||
|
s.GET("/login", showLogin)
|
||
|
s.POST("/login", handleLogin)
|
||
|
s.Route("/", func(r slim.RouteCollector) {
|
||
|
r.Use(authSession)
|
||
|
r.GET("/", showHome)
|
||
|
r.GET("/logout", handleLogout)
|
||
|
r.GET("/notify", handleNotify)
|
||
|
r.GET("/projects", listProjects)
|
||
|
r.GET("/new-projects", showNewProject)
|
||
|
r.POST("/new-projects", handleNewProject)
|
||
|
r.GET("/projects/:id", showProject)
|
||
|
r.DELETE("/projects/:id", deleteProject)
|
||
|
r.PUT("/projects/:id", updateProject)
|
||
|
r.POST("/build", buildProject)
|
||
|
})
|
||
|
return nil
|
||
|
}
|