generated from templates/go-generic
Dan Anglin
7d0336d3db
Add the metadata endpoint so that clients can get the server's authorization and token endpoints. Changes: - Add a config object to allow administrators to configure the binding address, binding port and domain name. - Add a target in the magefiles and a step in the CI workflow to run go vet. - Add the Dockerfile. - Replace the --address flag with the --config flag. - Add the metadata endpoint to the router to return a JSON document containing the URLs to the metadata and token endpoints.
38 lines
611 B
Go
38 lines
611 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Config struct {
|
|
BindAddress string `json:"bindAddress"`
|
|
Port int32 `json:"port"`
|
|
Domain string `json:"domain"`
|
|
}
|
|
|
|
func NewConfig(path string) (Config, error) {
|
|
path = filepath.Clean(path)
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return Config{}, fmt.Errorf(
|
|
"unable to read the config from %q: %w",
|
|
path,
|
|
err,
|
|
)
|
|
}
|
|
|
|
var cfg Config
|
|
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return Config{}, fmt.Errorf(
|
|
"unable to decode the JSON data: %w",
|
|
err,
|
|
)
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|