File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ .idea /
2+ main
3+ .DS_Store
Original file line number Diff line number Diff line change 1+ FROM golang:latest as build-env
2+
3+ ENV GO111MODULE=on
4+ ENV BUILDPATH=github.com/kplcloud/world
5+ # ENV GOPROXY=goproxy.io
6+ ENV GOPATH=/go
7+ RUN mkdir -p /go/src/${BUILDPATH}
8+ COPY ./ /go/src/${BUILDPATH}
9+ RUN cd /go/src/${BUILDPATH} && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -v
10+
11+ FROM alpine:latest
12+
13+ COPY --from=build-env /go/bin/world /go/bin/world
14+ WORKDIR /go/bin/
15+ CMD ["/go/bin/world" ]
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "net/http"
5+ "io"
6+ "os"
7+ "io/ioutil"
8+ )
9+
10+ func main () {
11+
12+ http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
13+ resp , err := http .Get ("http://hello:8080" )
14+ if err != nil {
15+ io .WriteString (w , err .Error ())
16+ return
17+ }
18+ defer resp .Body .Close ()
19+
20+ body , err := ioutil .ReadAll (resp .Body )
21+ if err != nil {
22+ io .WriteString (w , err .Error ())
23+ return
24+ }
25+
26+ io .WriteString (w , "name: " + os .Getenv ("HOSTNAME" )+ " ---> " + string (body ))
27+ })
28+
29+ http .HandleFunc ("/name" , func (writer http.ResponseWriter , request * http.Request ) {
30+ io .WriteString (writer , "this HOSTNAME is: " + os .Getenv ("HOSTNAME" ))
31+ })
32+
33+ if err := http .ListenAndServe (":8080" , nil ); err != nil {
34+ panic (err )
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments