Skip to content

Commit

Permalink
start developing bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Aug 10, 2024
1 parent fa873c7 commit e567bbe
Show file tree
Hide file tree
Showing 246 changed files with 16,956 additions and 11,771 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Flake check
run: |
nix check .
nix flake check .
build-images:
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion services/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ module github.com/cottand/selfhosted/services

go 1.22.3

require github.com/prometheus/client_golang v1.19.1
require (
github.com/monzo/terrors v0.0.0-20240312165114-073654f2beb9
github.com/prometheus/client_golang v1.19.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand Down
15 changes: 15 additions & 0 deletions services/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/monzo/terrors v0.0.0-20240312165114-073654f2beb9 h1:xAJ8jVUVP8YCaw0On91gvdWPolfdGurz8o/j8VP7AvM=
github.com/monzo/terrors v0.0.0-20240312165114-073654f2beb9/go.mod h1:nyaPwtZHdNA0F89nwV24ePEsxKlmV3i1dwBxajbqaM8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
Expand All @@ -14,7 +22,14 @@ github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSz
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
45 changes: 43 additions & 2 deletions services/lib/bedrock/init.go
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))
}
19 changes: 15 additions & 4 deletions services/s-portfolio-stats/main.go
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)
}
}
2 changes: 0 additions & 2 deletions services/vendor/github.com/cespare/xxhash/v2/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 7 additions & 22 deletions services/vendor/github.com/cespare/xxhash/v2/xxhash.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/vendor/github.com/cespare/xxhash/v2/xxhash_asm.go

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.

3 changes: 3 additions & 0 deletions services/vendor/github.com/golang/protobuf/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions services/vendor/github.com/golang/protobuf/CONTRIBUTORS

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.

Loading

0 comments on commit e567bbe

Please sign in to comment.