فهرست منبع

Загрузить файлы ''

gr784_MDA 3 سال پیش
والد
کامیت
cda0719331
5فایلهای تغییر یافته به همراه79 افزوده شده و 0 حذف شده
  1. 9 0
      Dockerfile
  2. 3 0
      go.mod
  3. 50 0
      lab2.go
  4. 9 0
      lab3.iml
  5. 8 0
      modules.xml

+ 9 - 0
Dockerfile

@@ -0,0 +1,9 @@
+FROM golang:latest
+
+WORKDIR /app
+COPY go.mod ./
+RUN go mod download
+COPY *.go ./
+RUN go build -o /lab2
+EXPOSE 8080
+CMD [ "/lab2" ]

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module lab3
+
+go 1.17

+ 50 - 0
lab2.go

@@ -0,0 +1,50 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+
+func GetOutboundIP() net.IP {
+	conn, err := net.Dial("udp", "8.8.8.8:80")
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer conn.Close()
+	localAddr := conn.LocalAddr().(*net.UDPAddr)
+	return localAddr.IP
+}
+func Status(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprint(w, "Начиков Даниил группа 784\n")
+	now := time.Now()
+	fmt.Fprint(w, "Now time is: ", now.Format(" 2006-01-02 3:4:5 pm\n"))
+	ip := GetOutboundIP().String()
+	regex := regexp.MustCompile("\\W[0-9]*\\W[0-9]*")
+	ipwithoutoctets := regex.ReplaceAllString(ip, ".*.*")
+	fmt.Fprint(w, "Ip is: ", ipwithoutoctets, " (without 2 octet)")
+
+}
+func OK(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "HTTP-статус 200")
+}
+
+func Info(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Начиков Даниил Группа 784")
+}
+
+func main() {
+
+	http.HandleFunc("/Info", Info)
+	http.HandleFunc("/OK", OK)
+	http.HandleFunc("/Status", Status)
+	err := http.ListenAndServe(":8080", nil)
+	if err != nil {
+		log.Fatal("ListenAndServe ", err)
+	}
+
+}

+ 9 - 0
lab3.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 8 - 0
modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/lab3.iml" filepath="$PROJECT_DIR$/.idea/lab3.iml" />
+    </modules>
+  </component>
+</project>