add model

This commit is contained in:
SmileRex
2025-01-23 05:37:47 +03:00
parent fa97251aa9
commit 1970f09678
3 changed files with 13 additions and 11 deletions

View File

@@ -11,17 +11,9 @@ import (
_ "github.com/go-sql-driver/mysql"
)
type Config struct {
Token string `yaml:"token"`
UserName string `yaml:"user_name"`
Password string `yaml:"password"`
HostName string `yaml:"host_name"`
DbName string `yaml:"db_name"`
}
type DataController struct{ DB *sql.DB }
func NewDB(config Config) *DataController {
func NewDB(config models.Config) *DataController {
dbaddr := fmt.Sprintf("%s:%s@tcp(%s)/%s", config.UserName, config.Password, config.HostName, config.DbName)
db, err := sql.Open("mysql", dbaddr)

9
src/models/config.go Normal file
View File

@@ -0,0 +1,9 @@
package models
type Config struct {
Token string `yaml:"token"`
UserName string `yaml:"user_name"`
Password string `yaml:"password"`
HostName string `yaml:"host_name"`
DbName string `yaml:"db_name"`
}