generated from VLADIMIR/template
add db filepath
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"evening_detective/internal/models"
|
||||
"log"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
@@ -13,11 +14,12 @@ type Repository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewRepository() (*Repository, error) {
|
||||
db, err := sql.Open("sqlite3", "data/db/store.db")
|
||||
func NewRepository(filepath string) (*Repository, error) {
|
||||
db, err := sql.Open("sqlite3", filepath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("load db from: %s", filepath)
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS teams (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, password TEXT);")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*pro
|
||||
if err := s.repository.AddApplications(ctx, actions); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
log(team, "add action", actions)
|
||||
addLog(team, "add action", actions)
|
||||
return &proto.AddActionRsp{}, nil
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func (s *Services) getTeam(ctx context.Context) (*models.Team, error) {
|
||||
return team, nil
|
||||
}
|
||||
|
||||
func log(team *models.Team, action string, v any) {
|
||||
func addLog(team *models.Team, action string, v any) {
|
||||
vJson, err := json.Marshal(v)
|
||||
if err == nil {
|
||||
fmt.Printf("Team %s: %s %s\n", team.Name, action, string(vJson))
|
||||
|
||||
Reference in New Issue
Block a user