-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
|
||
- name: Flake check | ||
run: | | ||
nix check . | ||
nix flake check . | ||
build-images: | ||
runs-on: ubuntu-latest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,53 @@ | ||
package bedrock | ||
|
||
import "net/http" | ||
import ( | ||
"fmt" | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
import ( | ||
"github.com/monzo/terrors" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
func Init() { | ||
http.Handle("/metrics", promhttp.Handler()) | ||
http.ListenAndServe(":2112", nil) | ||
|
||
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) | ||
|
||
slog.SetDefault(logger) | ||
|
||
slog.Info("Bedrock initialized") | ||
} | ||
|
||
func GetBaseConfig() (*BaseConfig, error) { | ||
port, ok := os.LookupEnv("HTTP_PORT") | ||
if !ok { | ||
return nil, terrors.New("no_env", "missing env config for http port", nil) | ||
} | ||
portNum, err := strconv.Atoi(port) | ||
if err != nil { | ||
return nil, terrors.Augment(err, "invalid env config for http port", nil) | ||
} | ||
host, ok := os.LookupEnv("HTTP_HOST") | ||
if !ok { | ||
return nil, terrors.New("no_env", "missing env config for http host", nil) | ||
} | ||
|
||
return &BaseConfig{ | ||
HttpHost: host, | ||
HttpPort: portNum, | ||
}, nil | ||
} | ||
|
||
type BaseConfig struct { | ||
HttpHost string | ||
HttpPort int | ||
} | ||
|
||
func (c *BaseConfig) HttpBind() string { | ||
return fmt.Sprint(c.HttpHost, ":", strconv.Itoa(c.HttpPort)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package main | ||
|
||
import "time" | ||
import ( | ||
"github.com/monzo/terrors" | ||
"log/slog" | ||
"net/http" | ||
) | ||
import "github.com/cottand/selfhosted/services/lib/bedrock" | ||
|
||
func main() { | ||
bedrock.Init() | ||
for { | ||
time.Sleep(3 * time.Second) | ||
println("hello world from service!") | ||
conf, err := bedrock.GetBaseConfig() | ||
if err != nil { | ||
slog.Error(err.Error()) | ||
panic(err) | ||
} | ||
|
||
err = http.ListenAndServe(conf.HttpBind(), nil) | ||
if err != nil { | ||
slog.Error(terrors.Augment(err, "failed to start server", nil).Error()) | ||
panic(err) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.