~poldi1405/gomod-recter

218184d8700537241a52652ce742d25c1db26f8c — Moritz Poldrack 1 year, 1 month ago 42490bc rewrite
add basic routing to entrypoint
1 files changed, 12 insertions(+), 5 deletions(-)

M internal/handler/entrypoint.go
M internal/handler/entrypoint.go => internal/handler/entrypoint.go +12 -5
@@ 1,11 1,12 @@
package handler

import (
	"strings"
	"bytes"

	"git.sr.ht/~poldi1405/glog"
	"github.com/spf13/viper"
	"github.com/valyala/fasthttp"
	"mpldr.codes/recter/project"
)

func Entrypoint(ctx *fasthttp.RequestCtx) {


@@ 13,10 14,16 @@ func Entrypoint(ctx *fasthttp.RequestCtx) {
		goGetHandler(ctx)
		return
	}
	if strings.HasPrefix(string(ctx.Path()), "/manhole/") && viper.GetBool("Manhole") {
		glog.Info("down the manhole")

	proj, ok := project.GetFullList()[string(ctx.Path())]

	switch {
	case viper.GetBool("Manhole") && bytes.HasPrefix(ctx.Path(), []byte("/manhole/")):
		glog.Debug("down the manhole")
		manholeHandler(ctx)
		return
	case ok:
		glog.Debug("requested project %s", proj.Path)
	default:
		handleError(fasthttp.StatusNotFound, ctx, nil)
	}
	glog.Info("no special case")
}