-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: introduced application dependency container
- Loading branch information
Showing
11 changed files
with
108 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"github.com/leanovate/mite-go/config" | ||
"github.com/leanovate/mite-go/mite" | ||
"github.com/mitchellh/go-homedir" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type Application struct { | ||
Conf config.Config | ||
MiteApi mite.Api | ||
Version string | ||
Commit string | ||
Date string | ||
} | ||
|
||
const defaultConfigFileName = ".mite.toml" | ||
|
||
// these flags will be overwritten during the build process by goreleaser | ||
var ( | ||
version = "dev" | ||
commit = "none" | ||
date = "none" | ||
) | ||
|
||
func NewApplication(fullConfigPath string) (*Application, error) { | ||
homeDirectory, err := homedir.Dir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if fullConfigPath == "" { | ||
fullConfigPath = filepath.Join(homeDirectory, defaultConfigFileName) | ||
} | ||
|
||
c := config.NewConfig(fullConfigPath) | ||
api := mite.NewApi(c.GetApiUrl(), c.GetApiKey(), version) | ||
|
||
if c.GetApiUrl() == "" { | ||
_, _ = fmt.Fprintln(os.Stderr, "please configure your API url by executing: 'mite config api.url=<your mite api url>'") | ||
} | ||
|
||
if c.GetApiKey() == "" { | ||
_, _ = fmt.Fprintln(os.Stderr, "please configure your API key by executing: 'mite config api.key=<your mite api key>'") | ||
} | ||
return &Application{Conf: c, MiteApi: api, Version: version, Commit: commit, Date: date}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.