add environ to loaded config files.

This commit is contained in:
xuu
2024-04-19 10:54:35 -06:00
parent bf54728f21
commit d9395811a4
10 changed files with 29 additions and 216 deletions

View File

@@ -8,6 +8,8 @@ import (
_ "github.com/lib/pq"
_ "modernc.org/sqlite"
_ "github.com/tursodatabase/go-libsql"
_ "go.sour.is/pkg/libsql_embed"
"github.com/oklog/ulid/v2"
"go.sour.is/passwd"
@@ -53,7 +55,7 @@ var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error
app.Register("local", conf)
http.Register()
mqtt.Register()
sql.Register()
svc.OnStop(sql.Register())
err = mercury.Registry.Configure(conf)
if err != nil {
@@ -90,13 +92,12 @@ func readConfig(ctx context.Context) (mercury.SpaceMap, error) {
for _, fn := range xdg.Find(wd+":"+xdg.EnvConfigDirs, "config.mercury") {
span.AddEvent(fmt.Sprint("config:", fn))
fd, err := os.Open(fn)
if err != nil {
content, err := os.ReadFile(fn)
if err != err {
return nil, err
}
defer fd.Close()
c, err := mercury.ParseText(fd)
c, err := mercury.ParseText(strings.NewReader(os.ExpandEnv(string(content))))
if err != nil {
return nil, err
}

View File

@@ -19,7 +19,7 @@ var apps service.Apps
var appName, version = service.AppName()
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
go func() {
<-ctx.Done()
defer cancel() // restore interrupt function
@@ -28,6 +28,7 @@ func main() {
log.Fatal(err)
os.Exit(1)
}
os.Exit(0)
}
func run(ctx context.Context) error {
level := slog.LevelError

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"log"
"net/http"
"strings"
@@ -22,10 +23,11 @@ var _ = apps.Register(20, func(ctx context.Context, svc *service.Harness) error
mux := mux.New()
s.Handler = cors.AllowAll().Handler(mux)
// s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// log.Println(r.URL.Path)
// mux.ServeHTTP(w, r)
// })
// print access requests
s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.URL.Path)
mux.ServeHTTP(w, r)
})
s.Addr = env.Default("EV_HTTP", ":4088")
if strings.HasPrefix(s.Addr, ":") {
@@ -40,7 +42,12 @@ var _ = apps.Register(20, func(ctx context.Context, svc *service.Harness) error
mux.Add(slice.FilterType[interface{ RegisterHTTP(*http.ServeMux) }](svc.Services...)...)
return s.ListenAndServe()
err := s.ListenAndServe()
if errors.Is(err, http.ErrServerClosed) {
return nil
}
return err
})
svc.OnStop(s.Shutdown)