gospt/main.go

41 lines
696 B
Go
Raw Permalink Normal View History

2023-01-07 07:40:39 +00:00
package main
import (
"context"
"fmt"
2023-01-08 00:03:43 +00:00
"log"
2023-01-07 07:40:39 +00:00
"os"
"path/filepath"
2023-01-08 05:34:31 +00:00
"gospt/internal/api"
2023-01-08 05:22:54 +00:00
"gospt/internal/auth"
"gospt/internal/config"
2023-01-08 05:26:06 +00:00
"gospt/internal/gctx"
2023-01-07 07:40:39 +00:00
)
func init() {
2023-01-09 05:08:51 +00:00
configPath, _ := os.UserConfigDir()
configDir := filepath.Join(configPath, "gospt")
2023-01-07 07:40:39 +00:00
config.LoadConfig(configDir)
}
func main() {
var err error
2023-01-08 00:03:43 +00:00
log.New(os.Stdout, "LOG:", 0)
2023-01-08 05:26:06 +00:00
ctx := gctx.NewContext(context.Background())
2023-01-08 05:22:54 +00:00
client, err := auth.GetClient(ctx)
2023-01-07 07:40:39 +00:00
if err != nil {
2023-01-09 05:08:51 +00:00
fmt.Println(err.Error())
return
2023-01-07 07:40:39 +00:00
}
2023-01-08 07:57:33 +00:00
currentUser, err := client.CurrentUser(ctx)
if err != nil {
panic(err.Error())
}
ctx.UserId = currentUser.ID
2023-01-08 05:34:31 +00:00
err = api.Run(ctx, client, os.Args[1:])
2023-01-07 07:40:39 +00:00
if err != nil {
fmt.Println(err)
}
}