Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More chore #46

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/unpack/index.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handler
package unpack

import (
"compress/bzip2"
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rec {
pname = "nar-serve";
version = "latest";
src = nixpkgs.lib.cleanSource ./.;
vendorHash = "sha256-IfXhuVwZf43FcQQ+i77aJHWG0auHBaHnKgTQJKa0L/M=";
vendorHash = "sha256-hi0KK+TQ3JG6LSMy8wnLDBRnTCwlfwo3ru22sbgX7dc=";
doCheck = false;
};

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ toolchain go1.22.5
require (
cloud.google.com/go/storage v1.43.0
github.com/aws/aws-sdk-go v1.55.3
github.com/go-chi/chi/v5 v5.1.0
github.com/google/go-cmp v0.6.0
github.com/klauspost/compress v1.17.9
github.com/stretchr/testify v1.9.0
github.com/ulikunitz/xz v0.5.12
github.com/urfave/negroni v1.0.0
)

require (
Expand All @@ -29,7 +30,6 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -87,8 +89,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g=
Expand Down
37 changes: 20 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"embed"
"net/http"
"io"
"log"
"net/http"
"os"

unpack "github.com/numtide/nar-serve/api/unpack"
"github.com/urfave/negroni"
"github.com/numtide/nar-serve/api/unpack"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)

//go:embed views/*
Expand Down Expand Up @@ -40,20 +43,21 @@ func main() {
addr = ":" + port
}

mux := http.NewServeMux()
mux.HandleFunc("/", indexHandler)
mux.HandleFunc("/healthz", healthzHandler)
mux.HandleFunc("/robots.txt", robotsHandler)
mux.HandleFunc(unpack.MountPath, unpack.Handler)
r := chi.NewRouter()

// Includes some default middlewares
// Serve static files from ./public
n := negroni.New(
negroni.NewRecovery(),
negroni.NewLogger(),
)
n.UseHandler(mux)
n.Run(addr)
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.CleanPath)
r.Use(middleware.GetHead)

r.Get("/", indexHandler)
r.Get("/healthz", healthzHandler)
r.Get("/robots.txt", robotsHandler)
r.Get(unpack.MountPath, unpack.Handler)

log.Println("addr=", addr)
log.Fatal(http.ListenAndServe(addr, r))
}

func getEnv(name, def string) string {
Expand All @@ -63,4 +67,3 @@ func getEnv(name, def string) string {
}
return value
}

Loading