taskcafe/api/cmd/citadelctl/main.go

56 lines
1.1 KiB
Go
Raw Normal View History

2020-04-10 04:40:22 +02:00
package main
import (
2020-05-27 23:18:50 +02:00
"context"
2020-04-10 04:40:22 +02:00
"fmt"
2020-05-27 23:18:50 +02:00
"io/ioutil"
_ "github.com/lib/pq"
"github.com/jmoiron/sqlx"
"github.com/jordanknott/project-citadel/api/pg"
"github.com/BurntSushi/toml"
// "github.com/jordanknott/project-citadel/api/router"
// "time"
2020-04-10 04:40:22 +02:00
)
2020-05-27 23:18:50 +02:00
type color struct {
Name string
Color string
Position int
}
type colors struct {
Color []color
}
2020-04-10 04:40:22 +02:00
func main() {
2020-05-27 23:18:50 +02:00
// dur := time.Hour * 24 * 7 * 30
// token, err := router.NewAccessTokenCustomExpiration("21345076-6423-4a00-a6bd-cd9f830e2764", dur)
// if err != nil {
// panic(err)
// }
// fmt.Println(token)
fmt.Println("seeding database...")
dat, err := ioutil.ReadFile("data/colors.toml")
2020-04-10 04:40:22 +02:00
if err != nil {
panic(err)
}
2020-05-27 23:18:50 +02:00
var labelColors colors
_, err = toml.Decode(string(dat), &labelColors)
if err != nil {
panic(err)
}
db, err := sqlx.Connect("postgres", "user=postgres password=test host=0.0.0.0 dbname=citadel sslmode=disable")
repository := pg.NewRepository(db)
for _, color := range labelColors.Color {
fmt.Printf("%v\n", color)
repository.CreateLabelColor(context.Background(), pg.CreateLabelColorParams{color.Name, color.Color, float64(color.Position)})
}
2020-04-10 04:40:22 +02:00
}