add project skeleton example
This commit is contained in:
parent
e9c4dff426
commit
9a8ac55819
16 changed files with 136 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -25,3 +25,5 @@ go.work
|
||||||
*.kdev4
|
*.kdev4
|
||||||
.kdev4/
|
.kdev4/
|
||||||
|
|
||||||
|
# the linux executable
|
||||||
|
server
|
||||||
|
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module git.0x0.st/ap/server
|
||||||
|
|
||||||
|
go 1.22.2
|
||||||
|
|
||||||
|
require github.com/pelletier/go-toml/v2 v2.2.1
|
20
go.sum
Normal file
20
go.sum
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
26
main.go
Normal file
26
main.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.0x0.st/ap/server/src/config"
|
||||||
|
_"git.0x0.st/ap/server/src/database"
|
||||||
|
_"git.0x0.st/ap/server/src/event"
|
||||||
|
_"git.0x0.st/ap/server/src/script"
|
||||||
|
_"git.0x0.st/ap/server/src/encryption"
|
||||||
|
_"git.0x0.st/ap/server/src/web"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this file acts as a bootstrapper for the server.
|
||||||
|
load config, init stuff, start webrouter etc etc.
|
||||||
|
*/
|
||||||
|
func main() {
|
||||||
|
cfg, err := config.LoadConfig(os.Getenv("HOME") + "/.ap/config.toml")
|
||||||
|
if err!= nil {
|
||||||
|
log.Fatal("failed to load config")
|
||||||
|
}
|
||||||
|
fmt.Println("Starting", cfg.Instance.Name, ", your personal", cfg.Instance.Software, "instance")
|
||||||
|
}
|
72
src/config/config.go
Normal file
72
src/config/config.go
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pelletier/go-toml/v2"
|
||||||
|
"os"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InstanceConfig struct {
|
||||||
|
Name string `toml:"name"`
|
||||||
|
Description string `toml:"description"`
|
||||||
|
Domain string `toml:"domain"`
|
||||||
|
Software string `toml:"software"`
|
||||||
|
}
|
||||||
|
type DatabaseConfig struct {
|
||||||
|
Host string `toml:"host"`
|
||||||
|
User string `toml:"user"`
|
||||||
|
Pass string `toml:"pass"`
|
||||||
|
DB string `toml:"db"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
IsDefault bool `toml:"-"`
|
||||||
|
Instance InstanceConfig `toml:"instance"`
|
||||||
|
Database DatabaseConfig `toml:"database"`
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
load config by path (filename),
|
||||||
|
if specified file does not exist, return the default config as hardcoded below.
|
||||||
|
*/
|
||||||
|
func LoadConfig(path string) (Config, error) {
|
||||||
|
// always have default config!
|
||||||
|
cfg := Config{
|
||||||
|
IsDefault : true,
|
||||||
|
Instance : InstanceConfig{
|
||||||
|
Name : "my-instance",
|
||||||
|
Description : "let's fucking goooo!",
|
||||||
|
Domain : "my.instance",
|
||||||
|
Software : "my-software",
|
||||||
|
},
|
||||||
|
Database : DatabaseConfig{
|
||||||
|
Host : "localhost",
|
||||||
|
User : "user",
|
||||||
|
Pass : "pass",
|
||||||
|
DB : "my-db",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
// return default config file
|
||||||
|
log.Println("WARNING: no config file. using defaults only")
|
||||||
|
return cfg, nil
|
||||||
|
} else {
|
||||||
|
// load existing config file
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err!=nil {
|
||||||
|
return cfg, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
content, err := ioutil.ReadAll(file)
|
||||||
|
if err!=nil {
|
||||||
|
return cfg, err
|
||||||
|
}
|
||||||
|
err = toml.Unmarshal(content, &cfg)
|
||||||
|
if err!=nil {
|
||||||
|
cfg.IsDefault = false
|
||||||
|
return cfg, err
|
||||||
|
}
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
}
|
1
src/database/db.go
Normal file
1
src/database/db.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package database
|
1
src/database/migrations.go
Normal file
1
src/database/migrations.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package database
|
1
src/database/objects.go
Normal file
1
src/database/objects.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package database
|
1
src/encryption/encryption.go
Normal file
1
src/encryption/encryption.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package encryption
|
1
src/event/scheduler.go
Normal file
1
src/event/scheduler.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package event
|
1
src/script/generic.go
Normal file
1
src/script/generic.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package script
|
1
src/script/prolog.go
Normal file
1
src/script/prolog.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package script
|
1
src/web/ap.go
Normal file
1
src/web/ap.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package web
|
1
src/web/mastoapi.go
Normal file
1
src/web/mastoapi.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package web
|
1
src/web/router.go
Normal file
1
src/web/router.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package web
|
1
src/web/webfinger.go
Normal file
1
src/web/webfinger.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package web
|
Loading…
Reference in a new issue