commit b81042aff07da0e0209a41695b122c89dcc6f453 Author: Shin'ya Minazuki Date: Tue Jan 20 09:06:35 2026 -0300 Awaken Signed-off-by: Shin'ya Minazuki diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f49f344 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/yomi + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d5f71a2 --- /dev/null +++ b/COPYING @@ -0,0 +1,12 @@ +Copyright (C) 2026 Shin'ya Minazuki + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee +is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c8aa84 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Yomi +Staging HTTP server for static files. diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..fd6e49b --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,25 @@ +# https://taskfile.dev + +version: '3' + +vars: + GOVER: 125 + VERSION: 0.0.0 + +tasks: + default: + cmds: + - task -l + silent: true + build: + desc: Build the program + cmds: + - go{{.GOVER}} build -ldflags='-w -X code.laidback.moe/yomi/cmd.Version={{.VERSION}}' -buildvcs=false -v + clean: + desc: Remove the program + cmds: + - rm -f yomi + tidy: + desc: Maintain go.mod + cmds: + - go{{.GOVER}} mod tidy diff --git a/cmd/http.go b/cmd/http.go new file mode 100644 index 0000000..9a97a71 --- /dev/null +++ b/cmd/http.go @@ -0,0 +1,33 @@ +package cmd + +import ( + "net/http" + "github.com/sirupsen/logrus" +) + +type ResponseWriter struct { + http.ResponseWriter + StatusCode int +} + +func (w *ResponseWriter) WriteHeader(statusCode int) { + w.StatusCode = statusCode + w.ResponseWriter.WriteHeader(statusCode) +} + +type Handler struct { + http.Handler +} + +func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + rw := &ResponseWriter{w, 0} + h.Handler.ServeHTTP(rw, r) + logrus.Println(r.RemoteAddr, r.Method, rw.StatusCode, r.URL) +} + +func HttpServe(dir string, bind string) { + handler := &Handler{http.FileServer(http.Dir(dir))} + http.Handle("/", handler) + logrus.Printf("[http] Listening on %s\n", bind) + logrus.Fatal(http.ListenAndServe(bind, nil)) +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..8cd3315 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,38 @@ +// Copyright (C) 2026 Shin'ya Minazuki +// Tjis file is part of Yomi +package cmd + +import ( + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +var ( + bind string + root string +) + +// String set at compile-time +var Version string + +var rootCmd = &cobra.Command{ + Use: "yomi", + Short: "A staging HTTP server for static content", + Run: func(cmd *cobra.Command, args []string) { + logrus.Printf("Yomi v%s is starting...", Version) + HttpServe(root, bind) + }, + Version: Version, +} + +func Execute() { + err := rootCmd.Execute() + if err != nil { + logrus.Fatal(err) + } +} + +func init() { + rootCmd.Flags().StringVarP(&bind, "bind", "b", "127.0.0.1:8000", "") + rootCmd.Flags().StringVarP(&root, "root", "r", ".", "") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cd33e6e --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module code.laidback.moe/yomi + +go 1.25.5 + +require ( + github.com/sirupsen/logrus v1.9.4 + github.com/spf13/cobra v1.10.2 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.9 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..058711a --- /dev/null +++ b/go.sum @@ -0,0 +1,22 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..3341f3e --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "code.laidback.moe/yomi/cmd" +) + +func main() { + cmd.Execute() +}