Explorar el Código

bumb v1.9.1 (#5635)

* Bumb Fiber v1.8.2

* Update go.mod

* Bumb v1.8.33

* Update go.mod

* Update versions

* bumb v1.9.1

Co-authored-by: Fenny <[email protected]>
Fenny hace 5 años
padre
commit
d147f74114

+ 2 - 1
frameworks/Go/fiber/README.md

@@ -6,11 +6,12 @@ This library is inspired by **[Express](https://expressjs.com/en/4x/api.html)**,
 * [Fiber](https://github.com/gofiber/fiber)
 
 ## Version Tested
-* [Fiber v0.8.0](https://github.com/gofiber/fiber/releases)
+* [Fiber v1.9.1](https://github.com/gofiber/fiber/releases)
 
 ## Test URLs
 * http://localhost:8080/json
 * http://localhost:8080/db
+* http://localhost:8080/fortune
 * http://localhost:8080/queries?queries=
 * http://localhost:8080/update?queries=
 * http://localhost:8080/plaintext

+ 50 - 46
frameworks/Go/fiber/benchmark_config.json

@@ -1,49 +1,53 @@
 {
   "framework": "fiber",
-  "tests": [{
-    "default": {
-      "json_url": "/json",
-      "db_url": "/db",
-      "query_url": "/queries?queries=",
-      "update_url": "/update?queries=",
-      "plaintext_url": "/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Platform",
-      "database": "Postgres",
-      "framework": "Fiber",
-      "language": "Go",
-      "flavor": "None",
-      "orm": "Raw",
-      "platform": "None",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "Fiber",
-      "notes": "",
-      "versus": "go"
-    },
-    "prefork": {
-      "json_url": "/json",
-      "db_url": "/db",
-      "query_url": "/queries?queries=",
-      "update_url": "/update?queries=",
-      "plaintext_url": "/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Platform",
-      "database": "Postgres",
-      "framework": "Fiber",
-      "language": "Go",
-      "flavor": "None",
-      "orm": "Raw",
-      "platform": "None",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "Fiber-prefork",
-      "notes": "",
-      "versus": "go"
+  "tests": [
+    {
+      "default": {
+        "json_url": "/j",
+        "db_url": "/d",
+        "query_url": "/q?q=",
+        "fortune_url": "/f",
+        "update_url": "/u?q=",
+        "plaintext_url": "/p",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "Postgres",
+        "framework": "Fiber",
+        "language": "Go",
+        "flavor": "None",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Fiber",
+        "notes": "",
+        "versus": "go"
+      },
+      "prefork": {
+        "json_url": "/j",
+        "db_url": "/d",
+        "query_url": "/q?q=",
+        "fortune_url": "/f",
+        "update_url": "/u?q=",
+        "plaintext_url": "/p",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "Postgres",
+        "framework": "Fiber",
+        "language": "Go",
+        "flavor": "None",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Fiber-prefork",
+        "notes": "",
+        "versus": "go"
+      }
     }
-  }]
-}
+  ]
+}

+ 4 - 3
frameworks/Go/fiber/fiber-prefork.dockerfile

@@ -1,14 +1,15 @@
 FROM golang:1.14
 
-ENV GO111MODULE on
 WORKDIR /fiber
 
 COPY ./src /fiber
 
-RUN go clean --modcache
+RUN go get github.com/valyala/quicktemplate/qtc
 
 RUN go mod download
 
-RUN go build -o server server.go
+RUN go generate ./templates
+
+RUN go build -ldflags="-s -w" -o server .
 
 CMD ./server -prefork

+ 4 - 3
frameworks/Go/fiber/fiber.dockerfile

@@ -1,14 +1,15 @@
 FROM golang:1.14
 
-ENV GO111MODULE on
 WORKDIR /fiber
 
 COPY ./src /fiber
 
-RUN go clean --modcache
+RUN go get github.com/valyala/quicktemplate/qtc
 
 RUN go mod download
 
-RUN go build -o server server.go
+RUN go generate ./templates
+
+RUN go build -ldflags="-s -w" -o server .
 
 CMD ./server

+ 3 - 2
frameworks/Go/fiber/src/go.mod

@@ -1,8 +1,9 @@
-module fiber
+module fiber/src
 
 go 1.14
 
 require (
-	github.com/gofiber/fiber v1.8.431
+	github.com/valyala/quicktemplate v1.4.1
+	github.com/gofiber/fiber v1.9.1
 	github.com/jackc/pgx/v4 v4.6.0
 )

+ 51 - 19
frameworks/Go/fiber/src/server.go

@@ -10,21 +10,34 @@ import (
 	"strconv"
 	"sync"
 
+	"fiber/src/templates"
+
 	"github.com/gofiber/fiber"
 	pgx "github.com/jackc/pgx/v4"
 	"github.com/jackc/pgx/v4/pgxpool"
 )
 
-var db *pgxpool.Pool
+var (
+	child bool
+	db    *pgxpool.Pool
+)
 
 const (
-	worldcount     = 10000
-	helloworld     = "Hello, World!"
-	worldselectsql = "SELECT id, randomNumber FROM World WHERE id = $1"
-	worldupdatesql = "UPDATE World SET randomNumber = $1 WHERE id = $2"
+	queryparam       = "q"
+	worldcount       = 10000
+	helloworld       = "Hello, World!"
+	htmlutf8         = "text/html; charset=utf-8"
+	worldselectsql   = "SELECT id, randomNumber FROM World WHERE id = $1"
+	worldupdatesql   = "UPDATE World SET randomNumber = $1 WHERE id = $2"
+	fortuneselectsql = "SELECT id, message FROM Fortune"
 )
 
 func main() {
+	for _, arg := range os.Args[1:] {
+		if arg == "-child" {
+			child = true
+		}
+	}
 
 	initDatabase()
 
@@ -34,11 +47,12 @@ func main() {
 		ServerHeader:  "go",
 	})
 
-	app.Get("/plaintext", plaintextHandler)
-	app.Get("/json", jsonHandler)
-	app.Get("/db", dbHandler)
-	app.Get("/queries", queriesHandler)
-	app.Get("/update", updateHandler)
+	app.Get("/p", plaintextHandler)
+	app.Get("/j", jsonHandler)
+	app.Get("/q", queriesHandler)
+	app.Get("/f", templateHandler)
+	app.Get("/d", dbHandler)
+	app.Get("/u", updateHandler)
 
 	app.Listen(8080)
 }
@@ -114,18 +128,12 @@ func ReleaseWorlds(w Worlds) {
 
 // initDatabase :
 func initDatabase() {
-	var child bool
-	for _, arg := range os.Args[1:] {
-		if arg == "-child" {
-			child = true
-		}
-	}
 	maxConn := runtime.NumCPU()
 	if maxConn == 0 {
 		maxConn = 8
 	}
-	if !child {
-		maxConn = maxConn * 4
+	if child {
+		maxConn = maxConn
 	}
 
 	var err error
@@ -151,6 +159,30 @@ func dbHandler(c *fiber.Ctx) {
 	ReleaseWorld(w)
 }
 
+// Frameworks/Go/fasthttp/src/server-postgresql/server.go#104
+func templateHandler(c *fiber.Ctx) {
+	rows, _ := db.Query(context.Background(), fortuneselectsql)
+
+	var f templates.Fortune
+	fortunes := make([]templates.Fortune, 0, 16)
+	for rows.Next() {
+		_ = rows.Scan(&f.ID, &f.Message)
+		fortunes = append(fortunes, f)
+	}
+	rows.Close()
+	fortunes = append(fortunes, templates.Fortune{
+		Message: "Additional fortune added at request time.",
+	})
+
+	sort.Slice(fortunes, func(i, j int) bool {
+		return fortunes[i].Message < fortunes[j].Message
+	})
+
+	c.Set(fiber.HeaderContentType, htmlutf8)
+
+	templates.WriteFortunePage(c.Fasthttp, fortunes)
+}
+
 // queriesHandler :
 func queriesHandler(c *fiber.Ctx) {
 	n := QueriesCount(c)
@@ -198,7 +230,7 @@ func RandomWorld() int {
 
 // QueriesCount :
 func QueriesCount(c *fiber.Ctx) int {
-	n, _ := strconv.Atoi(c.Query("queries"))
+	n, _ := strconv.Atoi(c.Query(queryparam))
 	if n < 1 {
 		n = 1
 	} else if n > 500 {

+ 22 - 0
frameworks/Go/fiber/src/templates/fortune.qtpl

@@ -0,0 +1,22 @@
+{% code
+type Fortune struct {
+	ID int32
+	Message string
+}
+%}
+
+{% func FortunePage(rows []Fortune) %}<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+{% for _, r := range rows %}
+<tr><td>{%d int(r.ID) %}</td><td>{%s r.Message %}</td></tr>
+{% endfor %}
+</table>
+</body>
+</html>
+{% endfunc %}

+ 87 - 0
frameworks/Go/fiber/src/templates/fortune.qtpl.go

@@ -0,0 +1,87 @@
+// Code generated by qtc from "fortune.qtpl". DO NOT EDIT.
+// See https://github.com/valyala/quicktemplate for details.
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:1
+package templates
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:1
+import (
+	qtio353123 "io"
+
+	qt343634 "github.com/valyala/quicktemplate"
+)
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:1
+var (
+	_ = qtio353123.Copy
+	_ = qt343634.AcquireByteBuffer
+)
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:2
+type Fortune struct {
+	ID      int32
+	Message string
+}
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:8
+func StreamFortunePage(qw271823 *qt343634.Writer, rows []Fortune) {
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:8
+	qw271823.N().S(`<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+`)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:16
+	for _, r := range rows {
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:16
+		qw271823.N().S(`
+<tr><td>`)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:17
+		qw271823.N().D(int(r.ID))
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:17
+		qw271823.N().S(`</td><td>`)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:17
+		qw271823.E().S(r.Message)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:17
+		qw271823.N().S(`</td></tr>
+`)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:18
+	}
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:18
+	qw271823.N().S(`
+</table>
+</body>
+</html>
+`)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+}
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+func WriteFortunePage(qq182734 qtio353123.Writer, rows []Fortune) {
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	qw271823 := qt343634.AcquireWriter(qq182734)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	StreamFortunePage(qw271823, rows)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	qt343634.ReleaseWriter(qw271823)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+}
+
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+func FortunePage(rows []Fortune) string {
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	qb423253 := qt343634.AcquireByteBuffer()
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	WriteFortunePage(qb423253, rows)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	qs435345 := string(qb423253.B)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	qt343634.ReleaseByteBuffer(qb423253)
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+	return qs435345
+//line frameworks/Go/fiber/src/templates/fortune.qtpl:22
+}