Files
Gokapi/Main.go
2021-04-07 22:38:29 +02:00

80 lines
2.5 KiB
Go
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
/**
Main routine
*/
import (
"Gokapi/src/configuration"
"Gokapi/src/environment"
"Gokapi/src/storage"
"Gokapi/src/webserver"
"embed"
"fmt"
"math/rand"
"os"
"time"
)
// Current version in readable form. The go generate call below
// needs to be modified as well
const VERSION = "1.1.3"
//go:generate sh "./.release/setVersionTemplate.sh" "1.1.3"
// Main routine that is called on startup
func main() {
checkPrimaryArguments()
rand.Seed(time.Now().UnixNano())
fmt.Println(logo)
fmt.Println("Gokapi v" + VERSION + " starting")
configuration.Load()
checkArguments()
go storage.CleanUp(true)
webserver.Start(&staticFolderEmbedded, &templateFolderEmbedded)
}
// Checks for command line arguments that have to be parsed before loading the configuration
func checkPrimaryArguments() {
if len(os.Args) > 1 {
if os.Args[1] == "--version" || os.Args[1] == "-v" {
fmt.Println("Gokapi v" + VERSION)
fmt.Println("Builder: " + environment.Builder)
fmt.Println("Build Date: " + environment.BuildTime)
fmt.Println("Docker Version: " + environment.IsDocker)
os.Exit(0)
}
}
}
// Checks for command line arguments that have to be parsed after loading the configuration
func checkArguments() {
if len(os.Args) > 1 {
if os.Args[1] == "--reset-pw" {
fmt.Println("Password change requested")
configuration.DisplayPasswordReset()
fmt.Println("Password has been changed!")
os.Exit(0)
}
}
}
// Embedded version of the "static" folder
// This contains JS files, CSS, images etc
//go:embed static
var staticFolderEmbedded embed.FS
// Embedded version of the "templates" folder
// This contains templates that Gokapi uses for creating the HTML output
//go:embed templates
var templateFolderEmbedded embed.FS
// ASCII art logo
const logo = `
██████  ██████  ██  ██  █████  ██████  ██ 
██       ██    ██ ██  ██  ██   ██ ██   ██ ██ 
██  ███ ██  ██ █████   ███████ ██████  ██ 
██  ██ ██  ██ ██  ██  ██   ██ ██      ██ 
 ██████   ██████  ██  ██ ██  ██ ██  ██ 
`