package main import ( "context" "log" "os" "SIMANC-WCS/app" "SIMANC-WCS/config" ) type App struct { ctx context.Context config.Config } func NewApp() *App { return &App{} } func (a *App) initApp() { // 初始化上下文 app.Context = a.ctx // 初始化资源数据目录 stat, err := os.Stat(app.DataPath) if err == nil { // 存在但不是文件夹时 if !stat.IsDir() { log.Panicf("initApp: [%s] is not a directory", app.DataPath) } return } // 如果不是"不存在"的错误时, 即: 其他错误 if !os.IsNotExist(err) { log.Panicf("initApp: %s", err) } if err = os.MkdirAll(app.DataPath, os.ModePerm); err != nil { log.Panicf("initApp: %s", err) } } // Exit 退出 func (a *App) Exit() { os.Exit(0) } func (a *App) startup(ctx context.Context) { a.ctx = ctx a.initApp() }