initial commit
commit
08ad92dfe7
@ -0,0 +1 @@
|
||||
.DS_STORE
|
@ -0,0 +1,21 @@
|
||||
package Configuration
|
||||
|
||||
// Configuration
|
||||
type Configuration struct {
|
||||
Domain string
|
||||
TLSCertificate string
|
||||
TLSKey string
|
||||
FileServer FileServerConfiguration
|
||||
}
|
||||
|
||||
// File Server Configuration
|
||||
type FileServerConfiguration struct {
|
||||
Active bool
|
||||
Routes []RoutesFileServerConfiguration
|
||||
}
|
||||
|
||||
// Routes File Server Configuration
|
||||
type RoutesFileServerConfiguration struct {
|
||||
ResourcePath string
|
||||
ServePath string
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package Configuration
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Load Configurations
|
||||
func LoadConfigurations(path string) ([]Configuration, error) {
|
||||
// Configurations
|
||||
var configurations []Configuration
|
||||
// Walk Configuration Directory
|
||||
err := filepath.Walk(path, func(path string, fileInfo fs.FileInfo, err error) error {
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// If File
|
||||
if fileInfo.IsDir() == false {
|
||||
// Read File
|
||||
configurationBytes, err := os.ReadFile(path)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Configuration
|
||||
var configuration Configuration
|
||||
// Unmarshal
|
||||
err = json.Unmarshal(configurationBytes, &configuration)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Add Configuration
|
||||
configurations = append(configurations, configuration)
|
||||
}
|
||||
// Return
|
||||
return nil
|
||||
})
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return []Configuration{}, err
|
||||
}
|
||||
// Return
|
||||
return configurations, nil
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package Configuration
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Validate Configurations
|
||||
func ValidateConfigurations(configurations []Configuration) error {
|
||||
// Configuration Number
|
||||
var configurationNumber uint
|
||||
// Configurations
|
||||
for configurationNumber = 0; configurationNumber < uint(len(configurations)); configurationNumber++ {
|
||||
// Validate Domain
|
||||
_, err := net.LookupHost(configurations[configurationNumber].Domain)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Certificate
|
||||
item, err := os.Stat(configurations[configurationNumber].TLSCertificate)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Check File
|
||||
if item.IsDir() == true {
|
||||
return errors.New("Error TLSCertificate Is Not A File")
|
||||
}
|
||||
// Key
|
||||
item, err = os.Stat(configurations[configurationNumber].TLSKey)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Check File
|
||||
if item.IsDir() == true {
|
||||
return errors.New("Error TLSKey Is Not A File")
|
||||
}
|
||||
// Validate File Server
|
||||
err = validateFileServer(configurations[configurationNumber].FileServer)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Return
|
||||
return nil
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package Configuration
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Validate File Server
|
||||
func validateFileServer(fileServerConfiguration FileServerConfiguration) error {
|
||||
// If Active
|
||||
if fileServerConfiguration.Active == true {
|
||||
// Route Number
|
||||
var routeNumber uint
|
||||
// Routes
|
||||
for routeNumber = 0; routeNumber < uint(len(fileServerConfiguration.Routes)); routeNumber++ {
|
||||
// Resource Path
|
||||
item, err := os.Stat(fileServerConfiguration.Routes[routeNumber].ResourcePath)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return errors.New("Error With Resource Path")
|
||||
}
|
||||
// Resource Path
|
||||
if item.IsDir() == false {
|
||||
return errors.New("Error With Resrouce Path")
|
||||
}
|
||||
// Serve Path
|
||||
if string(fileServerConfiguration.Routes[routeNumber].ServePath[0]) != "/" {
|
||||
return errors.New("Error With Serve Path")
|
||||
}
|
||||
// Serve Path
|
||||
_, err = url.ParseRequestURI(fileServerConfiguration.Routes[routeNumber].ServePath)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
return errors.New("Error With Serve Path")
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return
|
||||
return nil
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package Module
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"Gover/Configuration"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Add Modules
|
||||
func AddModules(configuration Configuration.Configuration, handler *http.ServeMux) {
|
||||
// Add Modules
|
||||
addFileServer(configuration, handler)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package Module
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"Gover/Configuration"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Add File Server
|
||||
func addFileServer(configuration Configuration.Configuration, handler *http.ServeMux) {
|
||||
// Check Active
|
||||
if configuration.FileServer.Active == true {
|
||||
// Route Number
|
||||
var routeNumber uint
|
||||
// Loop Over Routes
|
||||
for routeNumber = 0; routeNumber < uint(len(configuration.FileServer.Routes)); routeNumber++ {
|
||||
// Add File Server
|
||||
handler.Handle(configuration.Domain+configuration.FileServer.Routes[routeNumber].ServePath, http.StripPrefix(configuration.FileServer.Routes[routeNumber].ServePath, http.FileServer(http.Dir(configuration.FileServer.Routes[routeNumber].ResourcePath))))
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
# Make Directory
|
||||
mkdir ./build
|
||||
|
||||
# linux 386
|
||||
printf "Compiling linux-386 : "
|
||||
GOOS=linux GOARCH=386 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-386 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux amd64
|
||||
printf "Compiling linux-amd64 : "
|
||||
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-amd64 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux arm
|
||||
printf "Compiling linux-arm : "
|
||||
GOOS=linux GOARCH=arm go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-arm main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux arm64
|
||||
printf "Compiling linux-arm64 : "
|
||||
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-arm64 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux mips
|
||||
printf "Compiling linux-mips : "
|
||||
GOOS=linux GOARCH=mips go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-mips main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux mips64
|
||||
printf "Compiling linux-mips64 : "
|
||||
GOOS=linux GOARCH=mips64 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-mips64 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux mips64le
|
||||
printf "Compiling linux-mips64le : "
|
||||
GOOS=linux GOARCH=mips64le go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-mips64le main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux mipsle
|
||||
printf "Compiling linux-mipsle : "
|
||||
GOOS=linux GOARCH=mipsle go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-mipsle main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux ppc64
|
||||
printf "Compiling linux-ppc64 : "
|
||||
GOOS=linux GOARCH=ppc64 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-ppc64 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux ppc64le
|
||||
printf "Compiling linux-ppc64le : "
|
||||
GOOS=linux GOARCH=ppc64le go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-ppc64le main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux riscv64
|
||||
printf "Compiling linux-riscv64 : "
|
||||
GOOS=linux GOARCH=riscv64 go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-riscv64 main.go
|
||||
printf "Done\n"
|
||||
|
||||
# linux s390x
|
||||
printf "Compiling linux-s390x : "
|
||||
GOOS=linux GOARCH=s390x go build -ldflags "-X main.configurationDirectory=/var/Gover/Configuration" -o ./build/linux-s390x main.go
|
||||
printf "Done\n"
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"Domain": "example.com",
|
||||
|
||||
"TLSCertificate": "",
|
||||
"TLSKey": "",
|
||||
|
||||
"FileServer": {
|
||||
"Active": true,
|
||||
"Routes": [
|
||||
{
|
||||
"ResourcePath": "/www",
|
||||
"ServePath": "/"
|
||||
},
|
||||
{
|
||||
"ResourcePath": "/www",
|
||||
"ServePath": "/resources/"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
module Gover
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
)
|
@ -0,0 +1,4 @@
|
||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0=
|
||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
// Imports
|
||||
import (
|
||||
"Gover/Configuration"
|
||||
"Gover/Module"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var configurationDirectory string
|
||||
|
||||
// Main
|
||||
func main() {
|
||||
// HTTP Handler
|
||||
httpHandler := http.NewServeMux()
|
||||
// Configurations
|
||||
configurations, err := Configuration.LoadConfigurations(configurationDirectory)
|
||||
|
||||
println("Dir:")
|
||||
println(configurationDirectory)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Validate Configurations
|
||||
err = Configuration.ValidateConfigurations(configurations)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Configuration Number
|
||||
var configurationNumber uint
|
||||
// Loop Over Configurations
|
||||
for configurationNumber = 0; configurationNumber < uint(len(configurations)); configurationNumber++ {
|
||||
// Add Modules
|
||||
Module.AddModules(configurations[configurationNumber], httpHandler)
|
||||
}
|
||||
// Listen And Serve
|
||||
err = http.ListenAndServe(":80", httpHandler)
|
||||
// Handle Error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue