aprimoramento do arquivo conf'-'
This commit is contained in:
Binary file not shown.
@@ -15,11 +15,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func FileAuthGET() (map[string]interface{}, error) {
|
func FileAuthGET() (map[string]interface{}, error) {
|
||||||
file, err := os.Open(file_path + "zartigo.conf")
|
file, err := os.Open(file_path + "hdt.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
datafile := []byte("# nada por agora")
|
datafile := []byte("# configuraçoes\nport = 8085 # porta padrão que a api vai rodar\ndbhost = 127.0.0.1 # endereço do banco de dados [mysql ou mariadb]\ndbname = admin # nome do banco de dados [mysql ou mariadb]\ndbuser = rpg # usuario do banco de dados [mysql ou mariadb]\ndbpass = password # senha do banco de dados [mysql ou mariadb]\nredishost = 127.0.0.1 # endereço do banco de dados para cache [redis]\nredisport = 6379 # porta padrão do banco de dados cache [redis]\nsessionDuration = 24 # dureação de login [são em horas]\nsiteUnlock = http://exemplo.com # coloque o link do site onde o front-end vai ficar hospedado para permitir os cookies")
|
||||||
os.MkdirAll(file_path, 0755)
|
os.MkdirAll(file_path, 0755)
|
||||||
os.WriteFile(file_path+"zartigo.conf", datafile, 0644)
|
os.WriteFile(file_path+"hdt.conf", datafile, 0644)
|
||||||
log.Fatal("o arquivo de config não existia, mas foi criado no caminho " + file_path + " o configure e rode novamente.")
|
log.Fatal("o arquivo de config não existia, mas foi criado no caminho " + file_path + " o configure e rode novamente.")
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Helena_de_troia/config_data"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
@@ -19,12 +21,17 @@ func sessionCookie(id int, player string) (*http.Cookie, error) {
|
|||||||
"playerName": player,
|
"playerName": player,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := redisCL.HSet(ctx, sessionID, sessionInfo).Err()
|
load_data, _ := config_data.FileAuthGET()
|
||||||
|
sessionTime, err := strconv.Atoi(load_data["sessionDuration"].(string))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("sessionTime não foi encontrado ou não é um valor int, verifique o arquivo de configurações e tente novamente")
|
||||||
|
}
|
||||||
|
err = redisCL.HSet(ctx, sessionID, sessionInfo).Err()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("alguma coisa deu errado ao criar seu cookie de sessão")
|
return nil, fmt.Errorf("alguma coisa deu errado ao criar seu cookie de sessão")
|
||||||
}
|
}
|
||||||
err = redisCL.Expire(ctx, sessionID, 24*time.Hour).Err()
|
err = redisCL.Expire(ctx, sessionID, time.Duration(sessionTime)*time.Hour).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -36,7 +43,7 @@ func sessionCookie(id int, player string) (*http.Cookie, error) {
|
|||||||
//HttpOnly: true,
|
//HttpOnly: true,
|
||||||
//Secure: true,
|
//Secure: true,
|
||||||
//SameSite: http.SameSiteNoneMode,
|
//SameSite: http.SameSiteNoneMode,
|
||||||
Expires: time.Now().Add(24 * time.Hour),
|
Expires: time.Now().Add(time.Duration(sessionTime) * time.Hour),
|
||||||
}
|
}
|
||||||
return cookie, nil
|
return cookie, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,5 @@ var (
|
|||||||
".gif": true,
|
".gif": true,
|
||||||
}
|
}
|
||||||
cookieName string = "playerSession"
|
cookieName string = "playerSession"
|
||||||
|
load_data map[string]interface{}
|
||||||
)
|
)
|
||||||
|
|||||||
10
back_end/hdt.conf
Normal file
10
back_end/hdt.conf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# configuraçoes
|
||||||
|
port = 8085 # porta padrão que a api vai rodar
|
||||||
|
dbhost = 127.0.0.1 # endereço do banco de dados [mysql ou mariadb]
|
||||||
|
dbname = rpgzrox # nome do banco de dados [mysql ou mariadb]
|
||||||
|
dbuser = rpg # usuario do banco de dados [mysql ou mariadb]
|
||||||
|
dbpass = cronostrigo # senha do banco de dados [mysql ou mariadb]
|
||||||
|
redishost = 127.0.0.1 # endereço do banco de dados para cache [redis]
|
||||||
|
redisport = 6379 # porta padrão do banco de dados cache [redis]
|
||||||
|
sessionDuration = 24 # dureação de login [são em horas]
|
||||||
|
siteUnlock = http://192.168.1.102 # coloque o link do site onde o front-end vai ficar hospedado para permitir os cookies
|
||||||
@@ -20,7 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
load_data, _ := config_data.FileAuthGET()
|
load, _ := config_data.FileAuthGET()
|
||||||
|
load_data = load
|
||||||
log.Println("load config_data")
|
log.Println("load config_data")
|
||||||
|
|
||||||
Database(load_data["dbname"].(string), load_data["dbuser"].(string), load_data["dbpass"].(string), 3306, load_data["dbhost"].(string))
|
Database(load_data["dbname"].(string), load_data["dbuser"].(string), load_data["dbpass"].(string), 3306, load_data["dbhost"].(string))
|
||||||
@@ -36,11 +37,15 @@ func main() {
|
|||||||
|
|
||||||
log.Println("iniciando banco de dados cache")
|
log.Println("iniciando banco de dados cache")
|
||||||
redisCL = redis.NewClient(&redis.Options{
|
redisCL = redis.NewClient(&redis.Options{
|
||||||
Addr: "127.0.0.1:6379",
|
Addr: fmt.Sprintf("%s:%s", load_data["redishost"], load_data["redisport"]),
|
||||||
})
|
})
|
||||||
|
log.Printf("rodando redis em: %s:%s", load_data["redishost"], load_data["redisport"])
|
||||||
|
siteUnlock, ok := load_data["siteUnlock"].(string)
|
||||||
|
if !ok || siteUnlock == "" {
|
||||||
|
log.Fatal("Erro: siteUnlock ausente ou não é string")
|
||||||
|
}
|
||||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||||
AllowOrigins: []string{"http://192.168.1.102"},
|
AllowOrigins: []string{siteUnlock},
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# nada por agora
|
|
||||||
port = 8085
|
|
||||||
dbhost = 127.0.0.1
|
|
||||||
dbname = rpgzrox
|
|
||||||
dbuser = rpg
|
|
||||||
dbpass = cronostrigo
|
|
||||||
Reference in New Issue
Block a user