浏览代码

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
new file: docker/Dockerfile
new file: docker/app/2_laba.go

ARGON 2 年之前
父节点
当前提交
f769cc2633
共有 3 个文件被更改,包括 45 次插入23 次删除
  1. 9 0
      docker/Dockerfile
  2. 36 0
      docker/app/2_laba.go
  3. 0 23
      test.go

+ 9 - 0
docker/Dockerfile

@@ -0,0 +1,9 @@
+FROM golang
+
+WORKDIR /app
+
+COPY ./app .
+
+EXPOSE 8080
+
+CMD ["go", "run", "2_laba.go"]

+ 36 - 0
docker/app/2_laba.go

@@ -0,0 +1,36 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+func main() {
+	http.HandleFunc("/ok", sayhello)
+	http.HandleFunc("/info", sayhello1)
+	http.HandleFunc("/status", status)
+	err := http.ListenAndServe(":8080", nil)
+	if err != nil {
+		log.Fatal("ListenAndServe: ", err)
+	}
+}
+func sayhello(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "ok")
+	w.WriteHeader(200)
+}
+func sayhello1(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Незговоров Н.В.")
+}
+
+func status(w http.ResponseWriter, r *http.Request) {
+	time := time.Now()
+	ip, _, _ := net.SplitHostPort(r.RemoteAddr)
+	re := regexp.MustCompile(`[.].*[.]`)
+	fmt.Fprintln(w, re.ReplaceAllString(ip, ".*.*."))
+	fmt.Fprintf(w, "Незговоров Н.В."+"\n")
+	fmt.Fprintln(w, time.Format("2006-01-02 3:4:5 pm"))
+}

+ 0 - 23
test.go

@@ -1,23 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"log"
-	"net/http"
-)
-
-func main() {
-	http.HandleFunc("/ok", sayhello)
-	http.HandleFunc("/info", sayhello1)
-	err := http.ListenAndServe(":8080", nil)
-	if err != nil {
-		log.Fatal("ListenAndServe: ", err)
-	}
-}
-func sayhello(w http.ResponseWriter, r *http.Request) {
-	fmt.Fprintf(w, "ok")
-	w.WriteHeader(200)
-}
-func sayhello1(w http.ResponseWriter, r *http.Request) {
-	fmt.Fprintf(w, "Морозов М.А. 792")
-}