Added configuration from environment variables

This commit is contained in:
2025-02-08 16:27:33 +11:00
parent 1004dc9563
commit a842d09f96
7 changed files with 48 additions and 19 deletions

14
main.go
View File

@@ -4,7 +4,7 @@ import (
"context"
"embed"
"fmt"
"github.com/joho/godotenv"
"github.com/pkg/errors"
"io"
"net"
"net/http"
@@ -19,12 +19,12 @@ func run(ctx context.Context, w io.Writer) error {
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
config := &server.Config{
Host: "",
Port: "3333",
config, err := server.GetConfig()
if err != nil {
return errors.Wrap(err, "server.GetConfig")
}
srv := server.NewServer()
srv := server.NewServer(config)
httpServer := &http.Server{
Addr: net.JoinHostPort(config.Host, config.Port),
Handler: srv,
@@ -58,10 +58,6 @@ func run(ctx context.Context, w io.Writer) error {
var static embed.FS
func main() {
err := godotenv.Load(".env")
if err != nil {
panic(err.Error())
}
ctx := context.Background()
if err := run(ctx, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)