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
13 changes: 2 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ on:
pull_request:

jobs:
lint:
name: golangci-lint
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2.2.0
uses: golangci/golangci-lint-action@v2.4.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31
args: --timeout 5m

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
build:
name: Build
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions gen_cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

openssl genrsa -out server.key 2048
openssl ecparam -genkey -name secp384r1 -out server.key
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
15 changes: 14 additions & 1 deletion simplehttpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
type options struct {
ListenAddress string
Folder string
Certificate string
Key string
HTTPS bool
Verbose bool
}

Expand All @@ -20,6 +23,9 @@ var opts options
func main() {
flag.StringVar(&opts.ListenAddress, "listen", "0.0.0.0:8000", "Address:Port")
flag.StringVar(&opts.Folder, "path", ".", "Folder")
flag.BoolVar(&opts.HTTPS, "https", false, "HTTPS")
flag.StringVar(&opts.Certificate, "cert", "", "Certificate")
flag.StringVar(&opts.Key, "key", "", "Key")
flag.BoolVar(&opts.Verbose, "v", false, "Verbose")
flag.Parse()

Expand All @@ -28,7 +34,14 @@ func main() {
}

log.Printf("Serving %s on http://%s/...", opts.Folder, opts.ListenAddress)
fmt.Println(http.ListenAndServe(opts.ListenAddress, loglayer(http.FileServer(http.Dir(opts.Folder)))))
if opts.HTTPS {
if opts.Certificate == "" || opts.Key == "" {
log.Fatal("Certificate or Key file not specified")
}
fmt.Println(http.ListenAndServeTLS(opts.ListenAddress, opts.Certificate, opts.Key, loglayer(http.FileServer(http.Dir(opts.Folder)))))
} else {
fmt.Println(http.ListenAndServe(opts.ListenAddress, loglayer(http.FileServer(http.Dir(opts.Folder)))))
}
}

func loglayer(handler http.Handler) http.Handler {
Expand Down