Tests: goftm used for Go applications.

This commit is contained in:
Andrey Zelenkov
2019-08-14 14:06:28 +03:00
parent b3b7013eda
commit 8904c87c6b
8 changed files with 78 additions and 78 deletions

View File

@@ -1,22 +1,22 @@
package main package main
import ( import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
b, e := ioutil.ReadFile("404.html") b, e := ioutil.ReadFile("404.html")
if e == nil { if e == nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
io.WriteString(w, string(b)) io.WriteString(w, string(b))
} }
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,23 +1,23 @@
package main package main
import ( import (
"io" "fmt"
"os" "io"
"fmt" "net/http"
"strings" "nginx/unit"
"net/http" "os"
"nginx/unit" "strings"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
args := strings.Join(os.Args[1:], ",") args := strings.Join(os.Args[1:], ",")
w.Header().Add("X-Arg-0", fmt.Sprintf("%v", os.Args[0])) w.Header().Add("X-Arg-0", fmt.Sprintf("%v", os.Args[0]))
w.Header().Add("Content-Length", fmt.Sprintf("%v", len(args))) w.Header().Add("Content-Length", fmt.Sprintf("%v", len(args)))
io.WriteString(w, args) io.WriteString(w, args)
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,19 +1,19 @@
package main package main
import ( import (
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
cookie1, _ := r.Cookie("var1") cookie1, _ := r.Cookie("var1")
cookie2, _ := r.Cookie("var2") cookie2, _ := r.Cookie("var2")
w.Header().Set("X-Cookie-1", cookie1.Value) w.Header().Set("X-Cookie-1", cookie1.Value)
w.Header().Set("X-Cookie-2", cookie2.Value) w.Header().Set("X-Cookie-2", cookie2.Value)
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,13 +1,13 @@
package main package main
import ( import (
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) {} func handler(w http.ResponseWriter, r *http.Request) {}
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,17 +1,17 @@
package main package main
import ( import (
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Var-1", r.URL.Query().Get("var1")) w.Header().Set("X-Var-1", r.URL.Query().Get("var1"))
w.Header().Set("X-Var-2", r.URL.Query().Get("var2")) w.Header().Set("X-Var-2", r.URL.Query().Get("var2"))
w.Header().Set("X-Var-3", r.URL.Query().Get("var3")) w.Header().Set("X-Var-3", r.URL.Query().Get("var3"))
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,21 +1,21 @@
package main package main
import ( import (
"io" "fmt"
"fmt" "io"
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
var buf [32768]byte; var buf [32768]byte
len, _ := r.Body.Read(buf[:]) len, _ := r.Body.Read(buf[:])
w.Header().Add("Content-Length", fmt.Sprintf("%v", len)) w.Header().Add("Content-Length", fmt.Sprintf("%v", len))
io.WriteString(w, string(buf[:len])) io.WriteString(w, string(buf[:len]))
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,19 +1,19 @@
package main package main
import ( import (
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
w.Header().Set("X-Var-1", r.Form.Get("var1")) w.Header().Set("X-Var-1", r.Form.Get("var1"))
w.Header().Set("X-Var-2", r.Form.Get("var2")) w.Header().Set("X-Var-2", r.Form.Get("var2"))
w.Header().Set("X-Var-3", r.Form.Get("var3")) w.Header().Set("X-Var-3", r.Form.Get("var3"))
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }

View File

@@ -1,30 +1,30 @@
package main package main
import ( import (
"io" "fmt"
"fmt" "io"
"net/http" "net/http"
"nginx/unit" "nginx/unit"
) )
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
var buf [4096]byte; var buf [4096]byte
len, _ := r.Body.Read(buf[:]) len, _ := r.Body.Read(buf[:])
w.Header().Set("Request-Method", r.Method) w.Header().Set("Request-Method", r.Method)
w.Header().Set("Request-Uri", r.RequestURI) w.Header().Set("Request-Uri", r.RequestURI)
w.Header().Set("Server-Protocol", r.Proto) w.Header().Set("Server-Protocol", r.Proto)
w.Header().Set("Server-Protocol-Major", fmt.Sprintf("%v", r.ProtoMajor)) w.Header().Set("Server-Protocol-Major", fmt.Sprintf("%v", r.ProtoMajor))
w.Header().Set("Server-Protocol-Minor", fmt.Sprintf("%v", r.ProtoMinor)) w.Header().Set("Server-Protocol-Minor", fmt.Sprintf("%v", r.ProtoMinor))
w.Header().Set("Content-Length", fmt.Sprintf("%v", len)) w.Header().Set("Content-Length", fmt.Sprintf("%v", len))
w.Header().Set("Content-Type", r.Header.Get("Content-Type")) w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
w.Header().Set("Custom-Header", r.Header.Get("Custom-Header")) w.Header().Set("Custom-Header", r.Header.Get("Custom-Header"))
w.Header().Set("Http-Host", r.Header.Get("Host")) w.Header().Set("Http-Host", r.Header.Get("Host"))
io.WriteString(w, string(buf[:len])) io.WriteString(w, string(buf[:len]))
} }
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
unit.ListenAndServe(":7080", nil) unit.ListenAndServe(":7080", nil)
} }