Skip to content
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
5 changes: 3 additions & 2 deletions vindex/cmd/logandmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/transparency-dev/formats/log"
fnote "github.com/transparency-dev/formats/note"
"github.com/transparency-dev/incubator/vindex"
"github.com/transparency-dev/incubator/vindex/internal/web"
"github.com/transparency-dev/tessera"
"github.com/transparency-dev/tessera/api"
"github.com/transparency-dev/tessera/client"
Expand Down Expand Up @@ -305,14 +306,14 @@ func submitEntries(ctx context.Context, appender *tessera.Appender) {
}

func runWebServer(vi *vindex.VerifiableIndex, inLogDir, outLogDir string) (func(context.Context) error, error) {
web := NewServer(vi.Lookup)
srv := web.NewServer(vi.Lookup)

ilfs := http.FileServer(http.Dir(inLogDir))
olfs := http.FileServer(http.Dir(outLogDir))
r := mux.NewRouter()
r.PathPrefix("/inputlog/").Handler(http.StripPrefix("/inputlog/", ilfs))
r.PathPrefix("/outputlog/").Handler(http.StripPrefix("/outputlog/", olfs))
web.registerHandlers(r)
srv.RegisterHandlers(r)

listener, err := net.Listen("tcp", *listen)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions vindex/cmd/sumdbindex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
fnote "github.com/transparency-dev/formats/note"
"github.com/transparency-dev/incubator/sumdb"
"github.com/transparency-dev/incubator/vindex"
"github.com/transparency-dev/incubator/vindex/internal/web"
"github.com/transparency-dev/tessera"
"go.opentelemetry.io/otel/exporters/prometheus"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
Expand Down Expand Up @@ -216,13 +217,13 @@ func maintainMap(ctx context.Context, vi *vindex.VerifiableIndex) {
}

func runWebServer(inLog http.Handler, vi *vindex.VerifiableIndex, outLogDir string) (func(context.Context) error, error) {
web := NewServer(vi.Lookup)
srv := web.NewServer(vi.Lookup)

olfs := http.FileServer(http.Dir(outLogDir))
r := mux.NewRouter()
r.PathPrefix("/inputlog/").Handler(inLog)
r.PathPrefix("/outputlog/").Handler(http.StripPrefix("/outputlog/", olfs))
web.registerHandlers(r)
srv.RegisterHandlers(r)

listener, err := net.Listen("tcp", *listen)
if err != nil {
Expand Down
78 changes: 0 additions & 78 deletions vindex/cmd/sumdbindex/web.go

This file was deleted.

10 changes: 5 additions & 5 deletions vindex/cmd/logandmap/web.go → vindex/internal/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package web

import (
"context"
Expand All @@ -39,8 +39,8 @@ type Server struct {
lookup func(context.Context, [sha256.Size]byte) (api.LookupResponse, error)
}

// handleLookup handles GET requests for looking up map entries.
func (s Server) handleLookup(w http.ResponseWriter, r *http.Request) {
// HandleLookup handles GET requests for looking up map entries.
func (s Server) HandleLookup(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
hashStr, ok := vars["hash"]
if !ok {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (s Server) handleLookup(w http.ResponseWriter, r *http.Request) {
}
}

func (s Server) registerHandlers(r *mux.Router) {
r.HandleFunc("/vindex/lookup/{hash}", s.handleLookup).Methods("GET")
func (s Server) RegisterHandlers(r *mux.Router) {
r.HandleFunc("/vindex/lookup/{hash}", s.HandleLookup).Methods("GET")
r.Handle("/metrics", promhttp.Handler())
}
Loading