-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
40 lines (32 loc) · 782 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
func main(){
http.HandleFunc("/config", ConfigMap)
http.HandleFunc("/", Secret)
// http.HandleFunc("/", Hello)
http.ListenAndServe(":8000", nil)
}
/*func Hello(w http.ResponseWriter, r *http.Request){
name := os.Getenv("NAME")
age := os.Getenv("AGE")
fmt.Fprintf(w, "Hello, I'm %s. I'm %s", name, age)
}
*/
func ConfigMap(w http.ResponseWriter, r *http.Request){
data, err := ioutil.ReadFile("myfamily/family.txt")
if err != nil {
log.Fatalf("error reading file", err)
}
fmt.Fprintf(w, "My family:%s", string(data))
}
func Secret(w http.ResponseWriter, r *http.Request){
user := os.Getenv("USER")
password := os.Getenv("PASSWORD")
fmt.Fprintf(w, "User: %s. Password: %s", user, password)
}