mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-25 13:16:40 +00:00
Merge branch 'main' of github.com:gotosocial/server into main
This commit is contained in:
commit
baa2cbcca3
|
@ -21,7 +21,7 @@
|
|||
import (
|
||||
"os"
|
||||
|
||||
"github.com/gotosocial/gotosocial/cmd/server"
|
||||
"github.com/gotosocial/gotosocial/internal/server"
|
||||
"github.com/gotosocial/gotosocial/internal/consts"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -32,6 +32,7 @@ func main() {
|
|||
flagNames := consts.GetFlagNames()
|
||||
envNames := consts.GetEnvNames()
|
||||
app := &cli.App{
|
||||
Usage: "a fediverse social media server",
|
||||
Flags: []cli.Flag{
|
||||
// GENERAL FLAGS
|
||||
&cli.StringFlag{
|
||||
|
@ -47,6 +48,12 @@ func main() {
|
|||
EnvVars: []string{envNames.ApplicationName},
|
||||
Hidden: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagNames.ConfigPath,
|
||||
Usage: "Path to a yaml file containing gotosocial configuration. Values set in this file will be overwritten by values set as env vars or arguments",
|
||||
Value: "",
|
||||
EnvVars: []string{envNames.ConfigPath},
|
||||
},
|
||||
|
||||
// DATABASE FLAGS
|
||||
&cli.StringFlag{
|
||||
|
@ -76,9 +83,7 @@ func main() {
|
|||
&cli.StringFlag{
|
||||
Name: flagNames.DbPassword,
|
||||
Usage: "Database password",
|
||||
Value: "postgres",
|
||||
EnvVars: []string{envNames.DbPassword},
|
||||
FilePath: "./dbpass",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagNames.DbDatabase,
|
||||
|
|
37
example/config.yaml
Normal file
37
example/config.yaml
Normal file
|
@ -0,0 +1,37 @@
|
|||
# String. Log level to use throughout the application. Must be lower-case.
|
||||
# Options: ["debug","info","warn","error","fatal"]
|
||||
# Default: "info"
|
||||
logLevel: "info"
|
||||
|
||||
# String. Application name to use internally.
|
||||
# Examples: ["My Application","gotosocial"]
|
||||
# Default: "gotosocial"
|
||||
applicationName: "gotosocial"
|
||||
|
||||
# Config pertaining to the Gotosocial database connection
|
||||
db:
|
||||
# String. Database type.
|
||||
# Options: ["postgres"]
|
||||
# Default: "postgres"
|
||||
type: "postgres"
|
||||
|
||||
# String. Database address. Can be either an ipv4 address or a hostname.
|
||||
# Examples: ["localhost","my.db.host","127.0.0.1","192.111.39.110"]
|
||||
# Default: "localhost"
|
||||
address: "127.0.0.1"
|
||||
|
||||
# Int. Port for database connection.
|
||||
# Examples: [5432, 1234, 6969]
|
||||
# Default: 5432
|
||||
port: 5432
|
||||
|
||||
# String. Username for the database connection.
|
||||
# Examples: ["mydbuser","postgres","gotosocial"]
|
||||
# Default: "postgres"
|
||||
user: "postgres"
|
||||
|
||||
# REQUIRED
|
||||
# String. Password to use for the database connection
|
||||
# Examples: ["password123","verysafepassword","postgres"]
|
||||
# Default: ""
|
||||
password: ""
|
4
go.mod
4
go.mod
|
@ -9,16 +9,16 @@ require (
|
|||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/google/go-cmp v0.5.4 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/namsral/flag v1.7.4-pre // indirect
|
||||
github.com/onsi/ginkgo v1.15.0 // indirect
|
||||
github.com/onsi/gomega v1.10.5 // indirect
|
||||
github.com/sirupsen/logrus v1.8.0
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
github.com/urfave/cli/v2 v2.3.0 // indirect
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
|
||||
golang.org/x/sys v0.0.0-20210301091718-77cc2087c03b // indirect
|
||||
google.golang.org/protobuf v1.25.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
mellium.im/sasl v0.2.1 // indirect
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -77,8 +77,6 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
|||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/namsral/flag v1.7.4-pre h1:b2ScHhoCUkbsq0d2C15Mv+VU8bl8hAXV8arnWiOHNZs=
|
||||
github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7MsceFUpB5yDo=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
|
|
@ -19,22 +19,24 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/gotosocial/gotosocial/internal/db"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config contains all the configuration needed to run gotosocial
|
||||
type Config struct {
|
||||
DBConfig *db.Config `json:"db,omitempty"`
|
||||
LogLevel string `yaml:"logLevel"`
|
||||
ApplicationName string `yaml:"applicationName,omitempty"`
|
||||
DBConfig *db.Config `yaml:"db,omitempty"`
|
||||
}
|
||||
|
||||
// New returns a new config, or an error if something goes amiss.
|
||||
// The path parameter is optional, for loading a configuration json from the given path.
|
||||
func New(path string) (*Config, error) {
|
||||
var config *Config
|
||||
config := &Config{}
|
||||
if path != "" {
|
||||
var err error
|
||||
if config, err = loadFromFile(path); err != nil {
|
||||
|
@ -45,7 +47,7 @@ func New(path string) (*Config, error) {
|
|||
return config, nil
|
||||
}
|
||||
|
||||
// loadFromFile takes a path to a .json file and attempts to load a Config object from it
|
||||
// loadFromFile takes a path to a yaml file and attempts to load a Config object from it
|
||||
func loadFromFile(path string) (*Config, error) {
|
||||
bytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
|
@ -53,16 +55,16 @@ func loadFromFile(path string) (*Config, error) {
|
|||
}
|
||||
|
||||
config := &Config{}
|
||||
if err := json.Unmarshal(bytes, config); err != nil {
|
||||
if err := yaml.Unmarshal(bytes, config); err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal file at path %s: %s", path, err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// WithFlags returns a copy of this config object with flags set using the provided flags object
|
||||
func (c *Config) WithFlags(f Flags) *Config {
|
||||
return c
|
||||
// ParseFlags sets flags on the config using the provided Flags object
|
||||
func (c *Config) ParseFlags(f Flags) {
|
||||
|
||||
}
|
||||
|
||||
// Flags is a wrapper for any type that can store keyed flags and give them back
|
||||
|
|
|
@ -22,11 +22,12 @@
|
|||
|
||||
import "regexp"
|
||||
|
||||
// FlagNames is used for storing the names of the various flags used for
|
||||
// Flags is used for storing the names of the various flags used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
type FlagNames struct {
|
||||
type Flags struct {
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
ConfigPath string
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort string
|
||||
|
@ -37,38 +38,27 @@ type FlagNames struct {
|
|||
|
||||
// GetFlagNames returns a struct containing the names of the various flags used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
func GetFlagNames() FlagNames {
|
||||
return FlagNames{
|
||||
func GetFlagNames() Flags {
|
||||
return Flags{
|
||||
LogLevel: "log-level",
|
||||
ApplicationName: "application-name",
|
||||
ConfigPath: "config-path",
|
||||
DbType: "db-type",
|
||||
DbAddress: "db-address",
|
||||
DbPort: "db-port",
|
||||
DbUser: "db-users",
|
||||
DbUser: "db-user",
|
||||
DbPassword: "db-password",
|
||||
DbDatabase: "db-database",
|
||||
}
|
||||
}
|
||||
|
||||
// EnvNames is used for storing the environment variable keys used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
type EnvNames struct {
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort string
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbDatabase string
|
||||
}
|
||||
|
||||
// GetEnvNames returns a struct containing the names of the environment variable keys used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
func GetEnvNames() FlagNames {
|
||||
return FlagNames{
|
||||
func GetEnvNames() Flags {
|
||||
return Flags{
|
||||
LogLevel: "GTS_LOG_LEVEL",
|
||||
ApplicationName: "GTS_APPLICATION_NAME",
|
||||
ConfigPath: "GTS_CONFIG_PATH",
|
||||
DbType: "GTS_DB_TYPE",
|
||||
DbAddress: "GTS_DB_ADDRESS",
|
||||
DbPort: "GTS_DB_PORT",
|
||||
|
|
|
@ -46,14 +46,13 @@ type Service interface {
|
|||
|
||||
// Config provides configuration options for the database connection
|
||||
type Config struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
User string `json:"user,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
PasswordFile string `json:"passwordFile,omitempty"`
|
||||
Database string `json:"database,omitempty"`
|
||||
ApplicationName string `json:"applicationName,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Address string `yaml:"address,omitempty"`
|
||||
Port int `yaml:"port,omitempty"`
|
||||
User string `yaml:"user,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
Database string `yaml:"database,omitempty"`
|
||||
ApplicationName string `yaml:"applicationName,omitempty"`
|
||||
}
|
||||
|
||||
// NewService returns a new database service that satisfies the Service interface and, by extension,
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"syscall"
|
||||
|
||||
"github.com/gotosocial/gotosocial/internal/config"
|
||||
"github.com/gotosocial/gotosocial/internal/consts"
|
||||
"github.com/gotosocial/gotosocial/internal/db"
|
||||
"github.com/gotosocial/gotosocial/internal/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -38,8 +39,8 @@ func Run(c *cli.Context) error {
|
|||
return fmt.Errorf("error creating logger: %s", err)
|
||||
}
|
||||
|
||||
var gtsConfig *config.Config
|
||||
if gtsConfig, err = config.New(c.String("config")); err != nil {
|
||||
gtsConfig, err := config.New(c.String(consts.GetFlagNames().ConfigPath))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating config: %s", err)
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<html>
|
||||
<h1>
|
||||
{{ .title }}
|
||||
</h1>
|
||||
</html>
|
Loading…
Reference in a new issue