Created
June 12, 2021 15:13
-
-
Save eyberg/d417ba4e740c74982369585b37a0d0e2 to your computer and use it in GitHub Desktop.
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
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