3 ms·
This is cool - I didn't know you could have Go one-liners that look like this: go run github.com/eliben/static-server@latest I had to upgrade to Go 1.21 f
by simonw 3y ago
This is cool - I didn't know you could have Go one-liners that look like this:
go run github.com/eliben/static-server@latest
I had to upgrade to Go 1.21 for this to work - I was previously on Go 1.20. "brew upgrade go" worked for me.
Looks like almost the entire implementation is here, it's mostly CLI option parsing logic: https://github.com/eliben/static-server/blob/main/internal/server/server.go https://github.com/eliben/static-server/blob/main/internal/s...
- eliben 3y agoIndeed, the actual heavy lifting is done by the Go standard library; this line (https://github.com/eliben/static-server/blob/main/internal/server/server.go#L113 https://github.com/eliben/static-server/blob/main/internal/s...) is where the real magic happens (ignoring the logging middleware): fileHandler := serveLogger(serveLog, http.FileServer(http.Dir(rootDir)))
- benhoyt 3y agoYeah, with the "go 1.21.0" line in the go.mod file, it only works on Go 1.21. Here's what I get on Go 1.20: $ go run . go: errors parsing go.mod: .../static-server/go.mod:3: invalid go version '1.21.0': must match format 1.23 Eli, you might consider changing that to "go 1.20" so it works on Go 1.20 (and older, actually -- it's the 1.2.3 format that is getting in the way on Go pre-1.21).
- eliben 3y agoDone now; thanks for the note!