Compare commits

..

1 Commits

Author SHA1 Message Date
xuu
bb7f6b3878 chore: add keyoxide 2023-10-04 15:07:41 -06:00
11 changed files with 20 additions and 31 deletions

View File

@ -5,7 +5,7 @@
tasks: tasks:
- name: Copy build to remote - name: Copy build to remote
ansible.builtin.copy: ansible.builtin.copy:
src: ../ev src: ../build/ev
dest: /usr/local/bin/ev dest: /usr/local/bin/ev
owner: root owner: root
group: root group: root

View File

@ -11,6 +11,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-tags: true
- run: apt-get update && apt-get -y install ansible - run: apt-get update && apt-get -y install ansible
- name: Set up Go - name: Set up Go
@ -18,17 +22,15 @@ jobs:
with: with:
go-version: 1.21.1 go-version: 1.21.1
- name: Install - name: Build
run: go install -ldflags "-s -w" go.sour.is/tools/cmd/ev@main run: go build -ldflags "-s -w" -o ./build/ev ./cmd/ev
- run: mv $(go env GOPATH)/bin/ev ev
- name: Compress - name: Compress
uses: https://git.sour.is/actions/ghaction-upx@v2.4.0 uses: https://git.sour.is/actions/ghaction-upx@v2.4.0
with: with:
version: latest version: latest
files: | files: |
./ev ./build/ev
args: -fq args: -fq
- name: Deploy - name: Deploy

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
tools tools
sour.is-tools tmp

View File

@ -1,6 +1,6 @@
export PATH:=$(shell go env GOPATH)/bin:$(PATH) export PATH:=$(shell go env GOPATH)/bin:$(PATH)
export EV_DATA=mem: export EV_DATA=mem:
export EV_HTTP=:8085 export EV_HTTP=:8080
export WEBFINGER_DOMAINS=localhost export WEBFINGER_DOMAINS=localhost
.DEFAULT_GOAL := air .DEFAULT_GOAL := air
@ -15,7 +15,7 @@ endif
air . air .
run: run:
go build -buildvcs=true -o sour.is-tools ./cmd/ev && ./sour.is-tools go build . && ./tools
test: test:
go test -cover -race ./... go test -cover -race ./...

View File

@ -179,7 +179,7 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
return nil return nil
}) })
if err != nil { if err != nil {
span.AddEvent(err.Error()) span.RecordError(err)
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
@ -204,9 +204,8 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
peerResults.SetStreamID(aggPeer(peerID)) peerResults.SetStreamID(aggPeer(peerID))
err = s.es.Load(ctx, peerResults) err = s.es.Load(ctx, peerResults)
if err != nil && !errors.Is(err, ev.ErrNotFound) { if err != nil && !errors.Is(err, ev.ErrNotFound) {
span.AddEvent("peer not found") span.RecordError(fmt.Errorf("peer not found: %w", err))
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return
} }
var req *Request var req *Request
@ -222,9 +221,8 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
} }
} }
if req == nil { if req == nil {
span.AddEvent("request not found") span.RecordError(fmt.Errorf("request not found"))
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
return
} }
negotiator := contentnegotiation.NewNegotiator("application/json", "text/environment", "text/plain", "text/html") negotiator := contentnegotiation.NewNegotiator("application/json", "text/environment", "text/plain", "text/html")
@ -435,8 +433,8 @@ func (s *service) postResult(w http.ResponseWriter, r *http.Request, reqID strin
err := s.state.Use(ctx, func(ctx context.Context, state *state) error { err := s.state.Use(ctx, func(ctx context.Context, state *state) error {
var ok bool var ok bool
if _, ok = state.peers[peerID]; !ok { if _, ok = state.peers[peerID]; !ok {
log.Printf("peer not found: req=%s peer=%s\n", reqID, peerID) log.Printf("peer not found: %s\n", peerID)
return fmt.Errorf("peer not found: req=%s peer=%s", reqID, peerID) return fmt.Errorf("peer not found: %s", peerID)
} }
return nil return nil
@ -450,10 +448,9 @@ func (s *service) postResult(w http.ResponseWriter, r *http.Request, reqID strin
peerResults := &PeerResults{} peerResults := &PeerResults{}
peerResults.SetStreamID(aggPeer(peerID)) peerResults.SetStreamID(aggPeer(peerID))
err = s.es.Load(ctx, peerResults) err = s.es.Load(ctx, peerResults)
if err != nil && !errors.Is(err, ev.ErrNotFound) { if err != nil {
span.RecordError(fmt.Errorf("peer not found: req=%s peer=%s %w", reqID, peerID, err)) span.RecordError(fmt.Errorf("peer not found: %w", err))
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return
} }
if peerResults.Has(reqID) { if peerResults.Has(reqID) {

View File

@ -4,13 +4,10 @@ import (
"context" "context"
"errors" "errors"
"log" "log"
"log/slog"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"strconv"
"go.sour.is/pkg/env"
"go.sour.is/pkg/lg" "go.sour.is/pkg/lg"
"go.sour.is/pkg/service" "go.sour.is/pkg/service"
) )
@ -30,13 +27,6 @@ func main() {
} }
} }
func run(ctx context.Context) error { func run(ctx context.Context) error {
// TODO: make this configurable.
level := slog.LevelError
if ok, _ := strconv.ParseBool(env.Default("LOG_DEBUG", "FALSE")); ok {
level = slog.LevelDebug
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})))
svc := &service.Harness{} svc := &service.Harness{}
ctx, stop := lg.Init(ctx, appName) ctx, stop := lg.Init(ctx, appName)
svc.OnStop(stop) svc.OnStop(stop)

View File

@ -1,3 +1,4 @@
// <script src="https://unpkg.com/htmx.org@1.9.2" integrity="sha384-L6OqL9pRWyyFU3+/bjdSri+iIphTN/bvYyM37tICVyOJkWZLpP2vGn6VUEXgzg6h" crossorigin="anonymous"></script>
package main package main
import ( import (

View File

@ -1 +0,0 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

BIN
tmp/main

Binary file not shown.