本文整理匯總了Golang中github.com/facebookgo/stackerr.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getBuildVersionFromAPK
func (a *androidSymbolUploader) getBuildVersionFromAPK() (int, error) {
if a.Apk == "" {
return 0, stackerr.New("Please provide apk file path.")
}
if a.AAPT == "" {
androidHome := os.Getenv("ANDROID_HOME")
if androidHome == "" {
androidHome = os.Getenv("ANDROID_SDK")
}
if androidHome == "" {
return 0, stackerr.New("Cannot find aapt, you might need to set ANDROID_HOME.")
}
aapt, err := a.getAAPT(androidHome)
if err != nil {
return 0, err
}
a.AAPT = aapt
}
bytes, err := exec.Command(a.AAPT, "dump", "badging", a.Apk).Output()
if err != nil {
return 0, stackerr.Wrap(err)
}
return parseVersionFromBytes(bytes)
}
示例2: NewDaemon
func NewDaemon(options ...DaemonOption) (*daemon, error) {
d := &daemon{}
for _, option := range options {
option(d)
}
if d.log == nil {
return nil, stackerr.New("A logger must be provided")
}
if d.host == "" {
return nil, stackerr.New("Host name/IP must be provided")
}
if d.port == "" {
return nil, stackerr.New("Host port must be provided")
}
if err := d.validateFile(); err != nil {
return nil, err
}
cm, err := dyconf.NewManager(d.fileName)
if err != nil {
return nil, err
}
d.confManager = cm
return d, nil
}
示例3: AddSelectedParseApp
func AddSelectedParseApp(
appName string,
appConfig *parsecli.ParseAppConfig,
args []string,
makeDefault, verbose bool,
e *parsecli.Env,
) error {
config, err := parsecli.ConfigFromDir(e.Root)
if err != nil {
return err
}
parseConfig, ok := config.(*parsecli.ParseConfig)
if !ok {
return stackerr.New("Invalid Cloud Code config.")
}
// add app to config
if _, ok := parseConfig.Applications[appName]; ok {
return stackerr.Newf("App %s has already been added", appName)
}
parseConfig.Applications[appName] = appConfig
if len(args) > 0 && args[0] != "" {
alias := args[0]
aliasConfig, ok := parseConfig.Applications[alias]
if !ok {
parseConfig.Applications[alias] = &parsecli.ParseAppConfig{Link: appName}
}
if ok && aliasConfig.GetLink() != "" {
fmt.Fprintf(e.Out, "Overwriting alias: %q to point to %q\n", alias, appName)
parseConfig.Applications[alias] = &parsecli.ParseAppConfig{Link: appName}
}
}
if makeDefault {
if _, ok := parseConfig.Applications[parsecli.DefaultKey]; ok {
return stackerr.New(`Default key already set. To override default, use command "parse default"`)
}
parseConfig.Applications[parsecli.DefaultKey] = &parsecli.ParseAppConfig{Link: appName}
}
if err := parsecli.StoreConfig(e, parseConfig); err != nil {
return err
}
if verbose {
fmt.Fprintf(e.Out, "Written config for %q\n", appName)
if makeDefault {
fmt.Fprintf(e.Out, "Set %q as default\n", appName)
}
}
return nil
}
示例4: TestStackErrorString
func TestStackErrorString(t *testing.T) {
t.Parallel()
h := newHarness(t)
defer h.Stop()
err := stackerr.New("error")
h.env.ErrorStack = false
errStr := errorString(h.env, err)
ensure.DeepEqual(t, errStr, "error")
h.env.ErrorStack = true
errStr = errorString(h.env, err)
ensure.StringContains(t, errStr, "error")
ensure.StringContains(t, errStr, ".go")
err = stackerr.Wrap(&parse.Error{Message: "message", Code: 1})
h.env.ErrorStack = false
errStr = errorString(h.env, err)
ensure.DeepEqual(t, errStr, "message")
h.env.ErrorStack = true
errStr = errorString(h.env, err)
ensure.StringContains(t, errStr, `parse: api error with code=1 and message="message`)
ensure.StringContains(t, errStr, ".go")
}
示例5: run
func (s *symbolsCmd) run(e *env, c *context) error {
android := &androidSymbolUploader{
Path: s.path,
Apk: s.apk,
Manifest: s.manifest,
AAPT: s.aapt}
ios := &iosSymbolUploader{
Path: s.path,
SkipOsCheck: s.skipOsCheck}
switch {
case android.acceptsPath():
if err := android.validate(); err != nil {
return err
}
fmt.Fprintln(e.Out, "Uploading Android symbol files...")
return android.uploadSymbols(e)
case ios.acceptsPath():
if err := ios.validate(); err != nil {
return err
}
fmt.Fprintln(e.Out, "Uploading iOS symbol files...")
return ios.uploadSymbols(e)
default:
if s.path == "" {
return stackerr.New("Please specify path to symbol files")
}
return stackerr.Newf("Do not understand symbol files at : %s", s.path)
}
}
示例6: run
func (l *loginCmd) run(e *env) error {
fmt.Fprintf(e.Out,
`Please enter the email id you used to register with Parse
and an account key if you already generated it.
If you do not have an account key or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: `,
)
l.helpCreateToken(e)
var credentials credentials
fmt.Fprintf(e.Out, "Email: ")
fmt.Fscanf(e.In, "%s\n", &credentials.email)
fmt.Fprintf(e.Out, "Account Key: ")
fmt.Fscanf(e.In, "%s\n", &credentials.token)
_, err := (&apps{login: loginCmd{credentials: credentials}}).restFetchApps(e)
if err != nil {
if err == errAuth {
fmt.Fprintf(e.Err, `Sorry, we do not have a user with this email and account key.
Please follow instructions at %s to generate a new account key.
`,
keysURL,
)
} else {
fmt.Fprintf(e.Err, "Unable to validate token with error:\n%s\n", err)
}
return stackerr.New("Could not store credentials. Please try again.")
}
err = l.storeCredentials(e, &credentials)
if err == nil {
fmt.Fprintln(e.Out, "Successfully stored credentials.")
}
return stackerr.Wrap(err)
}
示例7: deployTriggerHook
func (h *Hooks) deployTriggerHook(e *parsecli.Env, op *hookOperation) error {
if op.Trigger == nil {
return stackerr.New("cannot deploy nil trigger hook")
}
exists, err := h.triggerHookExists(e, op.Trigger.ClassName, op.Trigger.TriggerName)
if err != nil {
return err
}
restOp, suppressed, err := h.checkStrictMode(op.Method, exists)
if err != nil {
return err
}
trigger := &triggerHooksCmd{Trigger: op.Trigger, All: false}
switch restOp {
case "POST":
return trigger.triggerHooksCreate(e, nil)
case "PUT":
return trigger.triggerHooksUpdate(e, nil)
case "DELETE":
if suppressed {
return nil
}
return trigger.triggerHooksDelete(e, nil)
}
return stackerr.Wrap(errInvalidFormat)
}
示例8: deployFunctionHook
func (h *Hooks) deployFunctionHook(e *parsecli.Env, op *hookOperation) error {
if op.Function == nil {
return stackerr.New("cannot deploy nil function hook")
}
exists, err := h.functionHookExists(e, op.Function.FunctionName)
if err != nil {
return err
}
restOp, suppressed, err := h.checkStrictMode(op.Method, exists)
if err != nil {
return err
}
function := &functionHooksCmd{Function: op.Function}
switch restOp {
case "POST":
return function.functionHooksCreate(e, nil)
case "PUT":
return function.functionHooksUpdate(e, nil)
case "DELETE":
if suppressed {
return nil
}
return function.functionHooksDelete(e, nil)
}
return stackerr.Wrap(errInvalidFormat)
}
示例9: accountKey
func (c *configureCmd) accountKey(e *env) error {
token, err := c.login.helpCreateToken(e)
if err != nil {
return err
}
credentials := credentials{token: token}
_, err = (&apps{login: login{credentials: credentials}}).restFetchApps(e)
if err != nil {
if err == errAuth {
fmt.Fprintf(e.Err,
`Sorry, the account key you provided is not valid.
Please follow instructions at %s to generate a new account key.
`,
keysURL,
)
} else {
fmt.Fprintf(e.Err, "Unable to validate token with error:\n%s\n", err)
}
return stackerr.New("Could not store credentials. Please try again.")
}
err = c.login.storeCredentials(e, &credentials)
if err == nil {
fmt.Fprintln(e.Out, "Successfully stored credentials.")
}
return stackerr.Wrap(err)
}
示例10: setVersion
func (j *jsSDKCmd) setVersion(e *env, c *context) error {
allVersions, err := j.getAllJSSdks(e)
if err != nil {
return err
}
valid := false
for _, version := range allVersions {
if version == j.newVersion {
valid = true
}
}
if !valid {
return stackerr.New("Invalid SDK version selected.")
}
conf, err := configFromDir(e.Root)
if err != nil {
return err
}
conf.getProjectConfig().Parse.JSSDK = j.newVersion
if err := storeProjectConfig(e, conf); err != nil {
return err
}
fmt.Fprintf(e.Out, "Current JavaScript SDK version is %s\n", conf.getProjectConfig().Parse.JSSDK)
return nil
}
示例11: PromptCreateWebhooks
func PromptCreateWebhooks(e *parsecli.Env) (string, error) {
selections := map[int]string{
1: "Heroku (https://www.heroku.com)",
2: "Parse (https://parse.com/docs/cloudcode/guide)",
}
msg := "Sorry! CLI supports only Parse Cloud Code and Heroku."
projectType := 0
for i := 0; i < 3; i++ {
fmt.Fprintf(
e.Out,
`Which of these providers would you like use for running your server code:
%d) %s
%d) %s
Type 1 or 2 to make a selection: `,
1, selections[1],
2, selections[2],
)
fmt.Fscanf(e.In, "%d\n", &projectType)
fmt.Fprintln(e.Out)
switch projectType {
case 1:
recordDecision(e, "heroku")
return "heroku", nil
case 2:
recordDecision(e, "parse")
return "parse", nil
}
fmt.Fprintln(e.Err, msg)
}
return "", stackerr.New(msg)
}
示例12: BestEffortDockerClient
// BestEfforDockerClient creates a docker client from one of:
//
// 1. Environment variables as defined in
// https://docs.docker.com/reference/commandline/cli/. Specifically
// DOCKER_HOST, DOCKER_TLS_VERIFY & DOCKER_CERT_PATH.
//
// 2. bootdocker, if darwin.
//
// 3. /run/docker.sock, if it exists.
//
// 4. /var/run/docker.sock, if it exists.
func BestEffortDockerClient() (*dockerclient.DockerClient, error) {
host := os.Getenv("DOCKER_HOST")
if host == "" {
if runtime.GOOS == "darwin" {
return Boot2DockerClient()
}
socketLocations := []string{"/run/docker.sock", "/var/run/docker.sock"}
for _, l := range socketLocations {
if _, err := os.Stat(l); err == nil {
c, err := dockerclient.NewDockerClient(fmt.Sprintf("unix://%s", l), nil)
if err != nil {
return nil, stackerr.Wrap(err)
}
return c, nil
}
}
return nil, stackerr.New("docker not configured")
}
if os.Getenv("DOCKER_TLS_VERIFY") != "" {
return DockerWithTLS(host, os.Getenv("DOCKER_CERT_PATH"))
}
c, err := dockerclient.NewDockerClient(host, nil)
if err != nil {
return nil, stackerr.Wrap(err)
}
return c, nil
}
示例13: TestMultiErrorString
func TestMultiErrorString(t *testing.T) {
t.Parallel()
h := newHarness(t)
defer h.Stop()
err := errgroup.MultiError(
[]error{
stackerr.New("error"),
stackerr.Wrap(&parse.Error{Message: "message", Code: 1}),
},
)
h.env.ErrorStack = false
errStr := errorString(h.env, err)
ensure.DeepEqual(t, errStr, "multiple errors: error | message")
h.env.ErrorStack = true
errStr = errorString(h.env, err)
ensure.StringContains(t, errStr, "multiple errors")
ensure.StringContains(t, errStr, `parse: api error with code=1 and message="message"`)
ensure.StringContains(t, errStr, ".go")
}
示例14: run
func (d *defaultCmd) run(e *env, args []string) error {
var newDefault string
if len(args) > 1 {
return stackerr.Newf("unexpected arguments, only an optional app name is expected: %v", args)
}
if len(args) == 1 {
newDefault = args[0]
}
config, err := configFromDir(e.Root)
if err != nil {
return err
}
if config.getNumApps() == 0 {
return stackerr.New("No apps are associated with this project. You can add some with parse add")
}
defaultApp := config.getDefaultApp()
switch newDefault {
case "":
return d.printDefault(e, defaultApp)
default:
return d.setDefault(e, newDefault, defaultApp, config)
}
}
示例15: run
func (h *logsCmd) run(e *parsecli.Env, ctx *parsecli.Context) error {
hkConfig, ok := ctx.AppConfig.(*parsecli.HerokuAppConfig)
if !ok {
return stackerr.New("Unexpected config format")
}
opts := &heroku.LogSessionCreateOpts{}
if h.num == 0 {
h.num = 50
}
//source := "app"
//opts.Source = &source
opts.Lines = &h.num
opts.Tail = &h.tail
session, err := e.HerokuAPIClient.LogSessionCreate(
hkConfig.HerokuAppID,
opts,
)
if err != nil {
return stackerr.Wrap(err)
}
resp, err := http.Get(session.LogplexURL)
if err != nil {
return stackerr.Wrap(err)
}
_, err = io.Copy(e.Out, resp.Body)
return stackerr.Wrap(err)
}