Add html, handler and db mock

This commit is contained in:
2020-10-08 12:43:59 +02:00
parent 41c14ff6bb
commit e2aa46c891
14 changed files with 672 additions and 1 deletions

38
.idea/workspace.xml generated
View File

@@ -1,12 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="52fd0845-10c0-4055-866d-7eb68e0b1470" name="Default Changelist" comment="" />
<list default="true" id="52fd0845-10c0-4055-866d-7eb68e0b1470" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/database/mainpage.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/handler/mainpage.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/models/washitem.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/routes/routes.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
</list>
</option>
</component>
<component name="GOROOT" path="/usr/lib/go" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -20,6 +35,7 @@
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="DefaultGoTemplateProperty" value="Go File" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="go.import.settings.migrated" value="true" />
@@ -61,5 +77,25 @@
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="746" y="367" key="FileChooserDialogImpl/0.0.1920.1080@0.0.1920.1080" timestamp="1602151353186" />
<state width="1872" height="278" key="GridCell.Tab.0.bottom" timestamp="1602152855261">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1872" height="278" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1602152855261" />
<state width="1872" height="278" key="GridCell.Tab.0.center" timestamp="1602152855260">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1872" height="278" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1602152855260" />
<state width="1872" height="278" key="GridCell.Tab.0.left" timestamp="1602152855260">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1872" height="278" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1602152855260" />
<state width="1872" height="278" key="GridCell.Tab.0.right" timestamp="1602152855261">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1872" height="278" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1602152855261" />
<state x="598" y="373" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1602151926873">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="598" y="373" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1602151926873" />
</component>
</project>

18
database/mainpage.go Normal file
View File

@@ -0,0 +1,18 @@
package database
import (
"github.com/gin-gonic/gin"
"time"
"trikotwaschliste/models"
)
func DbMainpage() gin.H {
var items []models.Washlist
items = append(items, models.Washlist{
Person: "Gerda",
Date: time.Now(),
IsWashed: true,
})
return gin.H{"items": items}
}

2
go.mod
View File

@@ -1,3 +1,5 @@
module trikotwaschliste
go 1.15
require github.com/gin-gonic/gin v1.6.3

47
go.sum Normal file
View File

@@ -0,0 +1,47 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

13
handler/mainpage.go Normal file
View File

@@ -0,0 +1,13 @@
package handler
import (
"github.com/gin-gonic/gin"
"net/http"
"trikotwaschliste/database"
)
func MainPage() gin.HandlerFunc {
return func(c *gin.Context) {
c.HTML(http.StatusAccepted, "index.html", database.DbMainpage())
}
}

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Medien Sammlung - Credits</title>
<link rel="stylesheet" type="text/css" href="/static/semantic.min.css">
</head>
<body>
{{template "navbar"}}
<div class="ui text center aligned container">
<br>
<h1 class="">Medien Sammlung <small>Version: {{ .version }}</small></h1>
<br>
<h2>Entwickler: structix</h2>
<h2>Git Repository: <a href="https://git.schoffit.net/structix/cdsammlung.git">Gitea Link</a></h2>
</div>
</body>
</html>

35
html/mainpage/index.html Normal file
View File

@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Trikotwaschliste</title>
<link rel="stylesheet" type="text/css" href="/static/semantic.min.css">
</head>
<body>
{{template "navbar"}}
<div class="ui center">
<h1 class="">Trikotwaschliste <small>Version: {{ .version }}</small></h1>
<table class="ui celled table">
<thead>
<tr>
<th>Person</th>
<th>Datum</th>
<th>Gewaschen?</th>
</tr>
</thead>
<tbody>
{{range .items}}
<tr>
<td>{{.Person}}</td>
<td>{{.Date}}</td>
<td>{{.IsWashed}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</body>
</html>

11
html/static/navbar.html Normal file
View File

@@ -0,0 +1,11 @@
{{define "navbar"}}
<div class="ui inverted menu">
<a href="/"><div class="header item">Trikotwaschliste</div></a>
<div class="right menu">
<a href="/querypage/create"><div class="item">Query</div></a>
<a href="/stats/interpret"><div class="item">Stats</div></a>
<a href="/credits"><div class="item">Credits</div></a>
</div>
</div>
{{end}}

372
html/static/semantic.min.css vendored Normal file

File diff suppressed because one or more lines are too long

11
html/static/semantic.min.js vendored Normal file

File diff suppressed because one or more lines are too long

40
html/static/style.css Normal file
View File

@@ -0,0 +1,40 @@
.title {
text-align: center;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
.button-green {background-color: #4CAF50;} /* Green */
.button-blue {background-color: #008CBA;} /* Blue */
.button-red {background-color: #f44336;} /* Red */
.button-gray {background-color: #e7e7e7; color: black;} /* Gray */
.button-black {background-color: #555555;} /* Black */
.center {
margin: auto;
width: 50%;
//border: 3px solid green;
padding: 10px;
}
tr:hover {background-color: #f5f5f5;}
th, td {
padding: 15px;
text-align: left;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}

47
main.go
View File

@@ -2,8 +2,55 @@ package main
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"trikotwaschliste/routes"
)
func main() {
fmt.Println("Hallo")
//gin.SetMode(gin.ReleaseMode)
r := gin.Default()
//get configuration
//cfg := model.Config{}
//if err := env.Parse(&cfg); err != nil {
// log.Printf("%+v\n", err)
//}
//Start postgres connection
//connPoolConfig := pgx.ConnPoolConfig{
// ConnConfig: pgx.ConnConfig{
// Host: cfg.DB_HOST,
// Port: cfg.DB_PORT,
// User: cfg.DB_USER,
// Password: cfg.DB_PASSWORD,
// Database: cfg.DB_DATABASE,
// },
// MaxConnections: cfg.DB_MAXCONNECTIONS,
//}
//pool, err := pgx.NewConnPool(connPoolConfig)
//for err != nil {
// pool, err = pgx.NewConnPool(connPoolConfig)
// if err != nil {
// log.Println(err.Error())
// log.Println("Unable to create connection pool. Retrying in 10sec...")
// }
// time.Sleep(10 * time.Second)
//}
var err error
r.LoadHTMLGlob("html/**/*")
r.Static("/static", "html/static")
//r.StaticFile("/favicon.ico", "html/favicon.ico")
//routes.RoutesInit(r, pool)
routes.RoutesInit(r)
err = r.Run("0.0.0.0:8082")
if err != nil {
log.Println("Something went wrong!")
}
}

9
models/washitem.go Normal file
View File

@@ -0,0 +1,9 @@
package models
import "time"
type Washlist struct {
Person string `json:"person"`
Date time.Time `json:"date"`
IsWashed bool `json:"iswashed"`
}

10
routes/routes.go Normal file
View File

@@ -0,0 +1,10 @@
package routes
import (
"github.com/gin-gonic/gin"
"trikotwaschliste/handler"
)
func RoutesInit(router *gin.Engine) {
router.GET("/", handler.MainPage())
}