* Corrections

This commit is contained in:
Daniel Legt 2022-05-15 15:21:21 +03:00
parent 21b8605fc0
commit e508d753ce
6 changed files with 48 additions and 3 deletions

View File

@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS `t_posts` (
`id` INT(11) NOT NULL,
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(256) NOT NULL DEFAULT '' COLLATE 'latin1_swedish_ci',
`content` MEDIUMTEXT NOT NULL COLLATE 'latin1_swedish_ci',
`ts` DATETIME NOT NULL DEFAULT current_timestamp(),

View File

@ -1,12 +1,21 @@
package post
import "errors"
import (
"errors"
"github.com/JustKato/FreePad/models/database"
)
var postList []*Post = []*Post{}
var postMap map[string]Post = make(map[string]Post)
func GetPostList() []*Post {
db := database.GetConn()
println(db)
return postList
}

View File

@ -2,4 +2,7 @@ module github.com/JustKato/FreePad
go 1.15
require github.com/gin-gonic/gin v1.7.7
require (
github.com/gin-gonic/gin v1.7.7
github.com/go-sql-driver/mysql v1.6.0
)

View File

@ -13,6 +13,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
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=

View File

@ -0,0 +1,30 @@
package database
import (
"database/sql"
"fmt"
"os"
"time"
_ "github.com/go-sql-driver/mysql"
)
func GetConn() *sql.DB {
user := os.Getenv("MYSQL_USER")
password := os.Getenv("MYSQL_PASSWORD")
dbname := os.Getenv("MYSQL_DATABASE")
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@/%s", user, password, dbname))
if err != nil {
panic(err)
}
// Set options
db.SetConnMaxLifetime(time.Minute * 5)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
return db
}

1
src/rundev.sh Executable file
View File

@ -0,0 +1 @@
export $(cat ../.env | xargs) && go run .