webserver

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
var GetManagedPortinformer = func(repo db.Repository, userID string) string {
	return repo.SelectUserPortinformer(userID)
}

GetManagedPortinformer retrieve managed portinformer

View Source
var GetUserID = func(repo db.Repository, authToken string) string {
	return repo.SelectUserID(authToken)
}

GetUserID retrive user id from auth token

View Source
var Login = func(c *gin.Context) {
	c.HTML(http.StatusOK, "login", gin.H{
		"data": "ok",
	})
}

Login form presentation

View Source
var Logout = func(c *gin.Context) {
	status, message := DestroySession(c)

	c.HTML(status, "logout", gin.H{
		"data": message,
	})
}

Logout destroy user session

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
var Welcome = func(c *gin.Context) {
	c.HTML(http.StatusOK, "welcome", gin.H{
		"data": "ok",
	})
}

Welcome render a landing page

Functions

func PathChecker

func PathChecker(list map[string]string) bool

PathChecker check if fs resource exist

func Run

func Run(s Server)

Run todo doc

Types

type Instance

type Instance struct {
	Engine *gin.Engine
}

Instance todo doc

func (*Instance) EngineBuild

func (i *Instance) EngineBuild() error

EngineBuild todo doc

func (*Instance) LoadSession

func (i *Instance) LoadSession()

LoadSession load session middleware

func (*Instance) Route

func (i *Instance) Route()

Route todo doc - Test delegate to Integration Testing

func (*Instance) Serve

func (i *Instance) Serve() error

Serve todo doc - Test in Unit testing

type Server

type Server interface {
	EngineBuild() error
	Route()
	Serve() error
}

Server todo doc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL