Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AnchoredNow = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "anchored_now", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
AnchoredNow call for currently anchored
var ArrivalPrevisionsNow = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "arrival_previsions_now", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
ArrivalPrevisionsNow call for arrival previsions active
var ArrivalsToday = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "arrivals_today", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
ArrivalsToday call for arrivals today
var AuthRequired = func(c *gin.Context) { session := sessions.Default(c) user := session.Get(sessionKey) if user == nil { c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) } return c.Next() }
AuthRequired middleware for restricted content
var CreateSession = func(c *gin.Context) bool { connector := db.Connector() repository := db.Repository{Conn: connector} session := sessions.Default(c) userID := GetUserID(repository, *ptoken) portinformer := GetManagedPortinformer(repository, userID) session.Set(portinformer, userID) session.Set(sessionKey, *ptoken) session.Set("managedPortinformer", portinformer) repository.Close() if err := session.Save(); err != nil { log.Println(err) return false } return true }
CreateSession build session
var DeparturePrevisionsNow = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "departure_previsions_now", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
DeparturePrevisionsNow call for arrival previsions active
var DeparturesToday = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "departures_today", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
DeparturesToday call for departures today
var DestroySession = func(c *gin.Context) (int, string) { session := sessions.Default(c) user := session.Get(sessionKey) if user == nil { return http.StatusBadRequest, "Invalid session token" } session.Delete(sessionKey) if err := session.Save(); err != nil { return http.StatusInternalServerError, "Failed to store session" } return http.StatusOK, "Successfully logged out" }
DestroySession destroy session
var Enter = func(c *gin.Context) { status, _ := ProcessAuth(c) if status == http.StatusOK { created := CreateSession(c) if !created { Login(c) } else { Welcome(c) } } else { Login(c) } }
Enter present auth form
var GetManagedPortinformer = func(repo db.Repository, userID string) string {
return repo.SelectUserPortinformer(userID)
}
GetManagedPortinformer retrieve managed portinformer
var GetUserID = func(repo db.Repository, authToken string) string {
return repo.SelectUserID(authToken)
}
GetUserID retrive user id from auth token
var Login = func(c *gin.Context) { c.HTML(http.StatusOK, "login", gin.H{ "data": "ok", }) }
Login form presentation
var Logout = func(c *gin.Context) { status, message := DestroySession(c) c.HTML(status, "logout", gin.H{ "data": message, }) }
Logout destroy user session
var MooringNow = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "mooring_now", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
MooringNow call for currently moored
var ProcessAuth = func(c *gin.Context) (int, string) { username := c.PostForm("user") password := c.PostForm("pass") lenUsername := len(strings.Trim(username, " ")) lenPassword := len(strings.Trim(password, " ")) if lenUsername == 0 || lenPassword == 0 { return http.StatusBadRequest, "Empty credentials" } resp, err := auth.SignOn(username, password) if err != nil { log.Println(err) } token, err := auth.ReadTokenAuth(resp) ptoken = &token if err != nil { return http.StatusUnauthorized, "Credentials error - Not authorized" } if len(token) == 0 { return http.StatusUnauthorized, "Token error - Not authorized" } return http.StatusOK, "Authorized" }
ProcessAuth auth processing
var ShiftingPrevisionsNow = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "shifting_previsions_now", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
ShiftingPrevisionsNow call for arrival previsions active
var ShippedGoodsToday = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "shipped_goods_today", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
ShippedGoodsToday todo doc
var TrafficListToday = func(c *gin.Context) { session := sessions.Default(c) portinformer := session.Get("managedPortinformer") c.HTML(http.StatusOK, "traffic_list_today", gin.H{ "SHIPFLOW_SERVER": os.Getenv("SHIPFLOW_SERVER"), "portinformer": portinformer, }) }
TrafficListToday call for today ro/ro pax
var Welcome = func(c *gin.Context) { c.HTML(http.StatusOK, "welcome", gin.H{ "data": "ok", }) }
Welcome render a landing page
Functions ¶
func PathChecker ¶
PathChecker check if fs resource exist