diff options
| -rw-r--r-- | Dockerfile | 16 | ||||
| -rw-r--r-- | go.mod | 7 | ||||
| -rw-r--r-- | go.sum | 14 | ||||
| -rw-r--r-- | main.go | 49 | ||||
| -rw-r--r-- | public/index.html | 60 |
5 files changed, 146 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7b372e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 as builder + +WORKDIR /usr/src/app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . + +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /bin/site . + +FROM scratch +COPY --from=builder /bin/site /app + +ENTRYPOINT ["/app"] + @@ -0,0 +1,7 @@ +module git.sr.ht/~a73x/home + +go 1.22.5 + +require go.uber.org/zap v1.27.0 + +require go.uber.org/multierr v1.10.0 // indirect @@ -0,0 +1,14 @@ +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -0,0 +1,49 @@ +package main + +import ( + "embed" + "io/fs" + "log" + "net/http" + "time" + + "go.uber.org/zap" +) + +//go:embed public/index.html +var content embed.FS + +func main() { + logger, _ := zap.NewProduction() + loggingMiddleware := func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + start := time.Now() + next.ServeHTTP(w, r) + logger.Info("request received", + zap.String("url", r.URL.Path), + zap.String("method", r.Method), + zap.Duration("duration", time.Since(start)), + zap.String("user-agent", r.UserAgent()), + ) + }) + } + + mux := http.NewServeMux() + + staticFs, err := fs.Sub(content, "public") + if err != nil { + log.Fatal(err) + } + + mux.Handle("/", http.FileServer(http.FS(staticFs))) + + server := http.Server{ + Addr: ":8080", + Handler: loggingMiddleware(mux), + } + + err = server.ListenAndServe() + if err != nil { + log.Fatal(err) + } +} diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..3a00176 --- /dev/null +++ b/public/index.html @@ -0,0 +1,60 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta name="description" content="Home for a73x" /> + <meta name="author" content="a73x" /> + <meta name="color-scheme" content="dark light" /> + <meta name="viewport" + content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" /> + <title>a73x</title> +</head> + +<body> + <h1>a73x</h1> + <ul> + <li>backend cloud software engineer</li> + <li>lang: go</li> + <li>infra: kubernetes</li> + </ul> + <h2>daily learnings</h2> + <h3>#go</h3> + <ul> + <li>layout packages by what they do, not by their abstract type</li> + <li>use channels sparingly. write synchronous methods and allow the caller to make it async</li> + <li><code>append</code> modifies the underlying slice, you'll only make this mistake once</li> + <li>define interfaces where you use them</li> + <li><code>make([]int, 5)</code> has a length and capacity of 5. <code>([]int, 0,5)</code> has a length + of 0 and capacity of 5. + <br /> + <code>append()</code> will only do what you want with the latter + </li> + <li>don't use <code>init()</code></li> + <li>TFBO (test, fix, benchmark, optimise)</li> + </ul> + <h3>#git</h3> + <ul> + <li><code>git commit --fixup=<COMMITSH></code> + <br /> + <code>git rebase origin/main --autosquash</code> + </li> + </ul> + + <h2>Books</h2> + <ul> + <li><a href=https://www.oreilly.com/library/view/designing-data-intensive-applications/9781491903063 />Designing + Data Intensive Applications</a></li> + <li><a href=https://www.oreilly.com/library/view/database-internals/9781492040330 />Database Internals + </a> + </li> + <li> + <a href=https://www.oreilly.com/library/view/efficient-go/9781098105709 /> Efficient Go</a> + + </li> + + </ul> + +</body> + +</html> |
