Skip to content

Instantly share code, notes, and snippets.

@eyberg
Created June 12, 2021 15:13
Show Gist options
  • Save eyberg/d417ba4e740c74982369585b37a0d0e2 to your computer and use it in GitHub Desktop.
Save eyberg/d417ba4e740c74982369585b37a0d0e2 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.ListenAndServe(":8080", nil)
}
# GO111MODULE=off GOOS=linux go build
# ops run -p 8080 g
# client
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("http://bob:8080")
if err != nil {
fmt.Println(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))
}
➜ z tree
.
├── config.json
├── etc
│   └── hosts
├── main.go
└── z
➜ z cat etc/hosts
10.0.2.2 bob
# ops run -c config.json z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment