-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd/web_server/iceland): Add simple built-in webserver which ser…
…ves photos from Iceland
- Loading branch information
1 parent
ecf154d
commit 276e9a3
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |