Skip to content

Commit

Permalink
feat(cmd/web_server/iceland): Add simple built-in webserver which ser…
Browse files Browse the repository at this point in the history
…ves photos from Iceland
  • Loading branch information
ondrejsika committed Nov 30, 2023
1 parent ecf154d commit 276e9a3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ import (
_ "github.com/sikalabs/slu/cmd/wait_for_it"
_ "github.com/sikalabs/slu/cmd/wait_for_tls"
_ "github.com/sikalabs/slu/cmd/watch"
_ "github.com/sikalabs/slu/cmd/web_server"
_ "github.com/sikalabs/slu/cmd/web_server/iceland"
_ "github.com/sikalabs/slu/cmd/windows"
_ "github.com/sikalabs/slu/cmd/windows/scoop_install"
_ "github.com/sikalabs/slu/cmd/wireguard"
Expand Down
33 changes: 33 additions & 0 deletions cmd/web_server/iceland/iceland.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package iceland

import (
"fmt"
"net/http"

"github.com/ondrejsika/go-iceland"
parentcmd "github.com/sikalabs/slu/cmd/web_server"
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "iceland",
Short: "Webserver with pictures from Iceland",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
server()
},
}

func init() {
parentcmd.Cmd.AddCommand(Cmd)
}

func server() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/jpeg")
w.WriteHeader(http.StatusOK)
w.Write(iceland.ICELAND_RIVER_AT_POOL_2022)
})
fmt.Println("Listen on 0.0.0.0:8000, see http://127.0.0.1:8000")
http.ListenAndServe(":8000", nil)
}
15 changes: 15 additions & 0 deletions cmd/web_server/web_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package web_server

import (
"github.com/sikalabs/slu/cmd/root"
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "web-server",
Short: "Set of embedded web servers",
}

func init() {
root.RootCmd.AddCommand(Cmd)
}

0 comments on commit 276e9a3

Please sign in to comment.