Compare commits
5 Commits
da3deedb0c
...
pongo-temp
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a7584d628 | |||
| c1997aaab5 | |||
| e92a56c393 | |||
| 45f6f19441 | |||
| 2b13292e3b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
/.vscode
|
||||
/__debug*
|
||||
/build
|
||||
/tmp
|
||||
/config.yaml
|
||||
|
||||
6
Makefile
6
Makefile
@ -1,2 +1,8 @@
|
||||
EXEC=iris-test
|
||||
|
||||
run:
|
||||
@air
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@go build -ldflags "-s -w" -o ./build/${EXEC} ./app/main.go
|
||||
|
||||
42
README.md
42
README.md
@ -14,3 +14,45 @@
|
||||
## Howto
|
||||
|
||||
- [Password Hashing (bcrypt)](https://gowebexamples.com/password-hashing/)
|
||||
|
||||
|
||||
## Bombardier benchmark
|
||||
|
||||
Pandora - Jet templating engine
|
||||
|
||||
```
|
||||
eden@pandora:[~/apps/sandbox/golang/iris-web-framework]: bombardier -c 100 -d 10s -l http://localhost:8000 ±[A1][main]
|
||||
Bombarding http://localhost:8000 for 10s using 100 connection(s)
|
||||
Done!
|
||||
Statistics Avg Stdev Max
|
||||
Reqs/sec 10542.16 2631.23 17296.86
|
||||
Latency 9.50ms 3.22ms 42.93ms
|
||||
Latency Distribution
|
||||
50% 8.77ms
|
||||
75% 11.86ms
|
||||
90% 15.31ms
|
||||
95% 17.86ms
|
||||
99% 23.90ms
|
||||
HTTP codes:
|
||||
1xx - 0, 2xx - 105258, 3xx - 0, 4xx - 0, 5xx - 0
|
||||
others - 0
|
||||
Throughput: 28.08MB/s
|
||||
```
|
||||
```
|
||||
eden@pandora:[~/apps/sandbox/golang/iris-web-framework]: bombardier -c 100 -d 10s -l http://localhost:8000/users ±[A1][main]
|
||||
Bombarding http://localhost:8000/users for 10s using 100 connection(s)
|
||||
Done!
|
||||
Statistics Avg Stdev Max
|
||||
Reqs/sec 1096.26 427.09 3211.54
|
||||
Latency 91.08ms 80.06ms 471.41ms
|
||||
Latency Distribution
|
||||
50% 78.37ms
|
||||
75% 156.58ms
|
||||
90% 191.60ms
|
||||
95% 223.49ms
|
||||
99% 309.59ms
|
||||
HTTP codes:
|
||||
1xx - 0, 2xx - 11060, 3xx - 0, 4xx - 0, 5xx - 0
|
||||
others - 0
|
||||
Throughput: 19.91MB/s
|
||||
```
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
27
app/main.go
27
app/main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"iris-test/app/common"
|
||||
"iris-test/app/views"
|
||||
"os"
|
||||
"time"
|
||||
@ -15,32 +16,32 @@ import (
|
||||
var redisDB *redis.Database
|
||||
|
||||
func createSessionEngine() *sessions.Sessions {
|
||||
redisAddr := fmt.Sprintf("%s:%d", Config.Redis.Host, Config.Redis.Port)
|
||||
redisAddr := fmt.Sprintf("%s:%d", common.Config.Redis.Host, common.Config.Redis.Port)
|
||||
|
||||
redisDB = redis.New(redis.Config{
|
||||
Network: "tcp",
|
||||
Addr: redisAddr,
|
||||
Timeout: time.Duration(30) * time.Second,
|
||||
MaxActive: 10,
|
||||
Username: Config.Redis.Username,
|
||||
Password: Config.Redis.Password,
|
||||
Database: Config.Redis.Database,
|
||||
Prefix: Config.Redis.Prefix,
|
||||
Username: common.Config.Redis.Username,
|
||||
Password: common.Config.Redis.Password,
|
||||
Database: common.Config.Redis.Database,
|
||||
Prefix: common.Config.Redis.Prefix,
|
||||
Driver: redis.GoRedis(), // defaults to this driver.
|
||||
// To set a custom, existing go-redis client, use the "SetClient" method:
|
||||
// Driver: redis.GoRedis().SetClient(customGoRedisClient)
|
||||
})
|
||||
|
||||
sessions_engine := sessions.New(sessions.Config{
|
||||
sessionsEngine := sessions.New(sessions.Config{
|
||||
Cookie: "_session_id",
|
||||
Expires: 0, // defaults to 0: unlimited life. Another good value is: 45 * time.Minute,
|
||||
AllowReclaim: true,
|
||||
CookieSecureTLS: true,
|
||||
})
|
||||
|
||||
sessions_engine.UseDatabase(redisDB)
|
||||
sessionsEngine.UseDatabase(redisDB)
|
||||
|
||||
return sessions_engine
|
||||
return sessionsEngine
|
||||
}
|
||||
|
||||
func createAccessLog() *accesslog.AccessLog {
|
||||
@ -83,18 +84,18 @@ func createApp() *iris.Application {
|
||||
accessLog := createAccessLog()
|
||||
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel(Config.Application.LogLevel)
|
||||
app.Logger().SetLevel(common.Config.Application.LogLevel)
|
||||
app.Use(sessionsEngine.Handler())
|
||||
app.UseRouter(accessLog.Handler)
|
||||
app.RegisterView(iris.Jet("./app/templates", ".jet").Reload(true))
|
||||
app.RegisterView(iris.Django("./app/templates", ".html").Reload(true))
|
||||
views.CreateRouter(app)
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
InitCfg()
|
||||
InitLogging()
|
||||
InitDB()
|
||||
common.InitCfg()
|
||||
common.InitLogging()
|
||||
common.InitDB()
|
||||
|
||||
app := createApp()
|
||||
defer redisDB.Close()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{{ title := "Hello world" }}
|
||||
{% set title = "Hello world" %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -26,7 +26,7 @@
|
||||
</ul>
|
||||
|
||||
<main>
|
||||
{{ yield mainContent() }}
|
||||
{% block mainContent %}{% endblock %}
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
@ -1,4 +1,4 @@
|
||||
{{ block usersTable(users) }}
|
||||
{% macro usersTable(users) %}
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -9,16 +9,16 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range users }}
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/users/{{ .Id }}">{{ .Id }}</a>
|
||||
<a href="/users/{{ user.Id }}">{{ user.Id }}</a>
|
||||
</td>
|
||||
<td>{{ .FirstName }}</td>
|
||||
<td>{{ .LastName }}</td>
|
||||
<td>{{ .Email }}</td>
|
||||
<td>{{ user.FirstName }}</td>
|
||||
<td>{{ user.LastName }}</td>
|
||||
<td>{{ user.Email }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ end }}
|
||||
{% endmacro %}
|
||||
28
app/templates/pages/index.html
Normal file
28
app/templates/pages/index.html
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends "/base/base.html" %}
|
||||
|
||||
|
||||
{% block mainContent %}
|
||||
|
||||
<div class="row">
|
||||
<form class="mb-5 col-4 ms-auto me-auto" method="post" action="/">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email address</label>
|
||||
<input type="email" name="email" class="form-control" value="edkirin@gmail.com">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Password</label>
|
||||
<input type="text" name="password" class="form-control" value="tralala">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">
|
||||
Submit
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="lead">
|
||||
<p>Bacon ipsum dolor amet leberkas kevin meatball pork loin beef ribs prosciutto, turducken bacon bresaola tri-tip. Strip steak flank shankle, sirloin short ribs shoulder meatball pork chop kevin ribeye jowl ham pork belly turducken jerky. Flank tongue short loin ham hock brisket turducken tail filet mignon cupim. Pork capicola buffalo kevin jowl chicken. Filet mignon brisket pig, landjaeger sausage cow fatback drumstick chicken buffalo tenderloin spare ribs.</p>
|
||||
<p>Swine shankle porchetta pancetta. Buffalo chicken turducken ground round kevin shoulder, salami pig t-bone beef ribs tri-tip tongue pork belly doner. Landjaeger meatloaf short loin biltong. Alcatra tongue shankle, tri-tip pancetta porchetta tenderloin corned beef pastrami rump. Bresaola chislic beef kielbasa sausage, ball tip burgdoggen boudin capicola short loin tenderloin buffalo landjaeger.</p>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@ -1,5 +1,5 @@
|
||||
{{ extends "/base/base.jet" }}
|
||||
{{ import "/components/table_component.jet" }}
|
||||
{{ extends "/base/base.html" }}
|
||||
{{ import "/components/table_component.html" }}
|
||||
|
||||
|
||||
{{ block mainContent() }}
|
||||
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func GetIndexPage(ctx iris.Context) {
|
||||
if err := ctx.View("pages/index.jet"); err != nil {
|
||||
if err := ctx.View("pages/index.html"); err != nil {
|
||||
showError(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@ -23,6 +23,7 @@ require (
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/fatih/structs v1.1.0 // indirect
|
||||
github.com/flosch/pongo2/v4 v4.0.2 // indirect
|
||||
github.com/flosch/pongo2/v6 v6.0.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@ -30,6 +30,8 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/flosch/pongo2/v4 v4.0.2 h1:gv+5Pe3vaSVmiJvh/BZa82b7/00YUGm0PIyVVLop0Hw=
|
||||
github.com/flosch/pongo2/v4 v4.0.2/go.mod h1:B5ObFANs/36VwxxlgKpdchIJHMvHB562PW+BWPhwZD8=
|
||||
github.com/flosch/pongo2/v6 v6.0.0 h1:lsGru8IAzHgIAw6H2m4PCyleO58I40ow6apih0WprMU=
|
||||
github.com/flosch/pongo2/v6 v6.0.0/go.mod h1:CuDpFm47R0uGGE7z13/tTlt1Y6zdxvr2RLT5LJhsHEU=
|
||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
|
||||
Reference in New Issue
Block a user