// NewApp creates a new app with Module m as the entry point. Unlike
// New, `start` is not automatically registered.
320774
func NewApp(m Module) *Service {
	svc := loadEnv(m, GetEnvironment())
	svc.commands["help"] = &Command{
		Keyword: "help <command>",
		Run: func(ctx *CommandContext) {
			ctx.RequireExactlyNArgs(1)
			cmd := svc.commands[ctx.Args[0]]
			if cmd == nil {
				fmt.Printf("Unknown command: %s\n", ctx.Args[0])
				return
			}
			fmt.Printf("Usage of %s %s\n", os.Args[0], cmd.Keyword)
			if cmd.Usage == "" {
				fmt.Println(cmd.ShortUsage)
			} else {
				fmt.Println(cmd.Usage)
			}
		},
		ShortUsage: "Additional info for <command>",
		Usage:      "Show additional info for <command>",
	}
	return svc
}
754650
func New(appName string) (*Checkpoint, error) {
	addr := os.Getenv("REDIS_URL")
	if addr == "" {
		addr = localhost
	}

	client := redis.NewClient(&redis.Options{Addr: addr})

	// verify we can ping server
	_, err := client.Ping().Result()
	if err != nil {
		return nil, err
	}

	return &Checkpoint{
		appName: appName,
		client:  client,
	}, nil
}
459153
func (s *MyMongo) New(appEnv *cfenv.App) *MyMongo {
	mongoServiceName := os.Getenv("MONGO_SERVICE_NAME")
	mongoURIName := os.Getenv("MONGO_URI_NAME")
	mongoDBName := os.Getenv("MONGO_DB_NAME")
	s.mongoCollName = os.Getenv("MONGO_COLLECTION_NAME")
	mongoService, err := appEnv.Services.WithName(mongoServiceName)

	if err != nil {
		panic(fmt.Sprintf("mongodb service name error: %s", err.Error()))
	}
	s.mongoConnectionURI = mongoService.Credentials[mongoURIName].(string)
	s.mongoDBName = mongoService.Credentials[mongoDBName].(string)
	s.connect()
	return s
}
200771
func New() *App {
	app := new(App)
	app.Server = new(http.Server)
	app.mds = make(middlewares, 0)
	app.settings = make(map[interface{}]interface{})

	env := os.Getenv("APP_ENV")
	if env == "" {
		env = "development"
	}
	app.Set(SetEnv, env)
	app.Set(SetServerName, "Gear/"+Version)
	app.Set(SetTrustedProxy, false)
	app.Set(SetBodyParser, DefaultBodyParser(2<<20)) // 2MB
	app.Set(SetURLParser, DefaultURLParser{})
	app.Set(SetLogger, log.New(os.Stderr, "", 0))
	app.Set(SetParseError, func(err error) HTTPError {
		return ParseError(err)
	})
	app.Set(SetOnError, func(ctx *Context, err HTTPError) {
		ctx.Error(err)
	})
	return app
}
196493
func (s *MyOAuth2) New(appEnv *cfenv.App) *MyOAuth2 {
	oauth2ServiceName := os.Getenv("OAUTH2_SERVICE_NAME")
	clientIdName := os.Getenv("OAUTH2_CLIENT_ID")
	clientSecretName := os.Getenv("OAUTH2_CLIENT_SECRET")
	oauth2Service, err := appEnv.Services.WithName(oauth2ServiceName)

	if err != nil {
		panic(fmt.Sprintf("oauth2 client service name error: %s", err.Error()))
	}
	s.ID = oauth2Service.Credentials[clientIdName].(string)
	s.Secret = oauth2Service.Credentials[clientSecretName].(string)
	return s
}
34358
func New(app string, opts ...Option) (*Ringpop, error) {
	var err error

	ringpop := &Ringpop{
		config: &configuration{
			App:           app,
			InitialLabels: make(swim.LabelMap),
		},
		logger: logging.Logger("ringpop"),
	}

	err = applyOptions(ringpop, defaultOptions)
	if err != nil {
		panic(fmt.Errorf("Error applying default Ringpop options: %v", err))
	}

	err = applyOptions(ringpop, opts)
	if err != nil {
		return nil, err
	}

	errs := checkOptions(ringpop)
	if len(errs) != 0 {
		return nil, fmt.Errorf("%v", errs)
	}

	ringpop.setState(created)

	return ringpop, nil
}
888250
func (client *MyInventoryClient) New(appEnv *cfenv.App) *MyInventoryClient {

  if strings.ToUpper(os.Getenv("DISPLAY_NEW_SERVICES")) == "YES" {
    client.Enabled = true
    client.ServiceBaseURL = getServiceBinding("inventory-service", "target-url", appEnv)
  } else {
    client.Enabled = false
  }
  return client
}
386549
func newApp() (app *cli.App) {
	app = cli.NewApp()
	app.Name = "global-store"
	app.Version = version
	if len(gitCommit) >= 8 {
		app.Version += "-" + gitCommit[:8]
	}
	app.Usage = "Swarm Global Store"

	// app flags (for all commands)
	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "verbosity",
			Value: 3,
			Usage: "Verbosity level.",
		},
		cli.StringFlag{
			Name:  "explorer-address",
			Value: "",
			Usage: "Chunk explorer HTTP listener address.",
		},
		cli.StringSliceFlag{
			Name:  "explorer-cors-origin",
			Value: nil,
			Usage: "Chunk explorer CORS origin (can be specified multiple times).",
		},
	}

	app.Commands = []cli.Command{
		{
			Name:    "http",
			Aliases: []string{"h"},
			Usage:   "Start swarm global store with HTTP server.",
			Action:  startHTTP,
			// Flags only for "start" command.
			// Allow app flags to be specified after the
			// command argument.
			Flags: append(app.Flags,
				cli.StringFlag{
					Name:  "dir",
					Value: "",
					Usage: "Data directory.",
				},
				cli.StringFlag{
					Name:  "addr",
					Value: "0.0.0.0:3033",
					Usage: "Address to listen for HTTP connections.",
				},
			),
		},
		{
			Name:    "websocket",
			Aliases: []string{"ws"},
			Usage:   "Start swarm global store with WebSocket server.",
			Action:  startWS,
			// Flags only for "start" command.
			// Allow app flags to be specified after the
			// command argument.
			Flags: append(app.Flags,
				cli.StringFlag{
					Name:  "dir",
					Value: "",
					Usage: "Data directory.",
				},
				cli.StringFlag{
					Name:  "addr",
					Value: "0.0.0.0:3033",
					Usage: "Address to listen for WebSocket connections.",
				},
				cli.StringSliceFlag{
					Name:  "origin",
					Value: nil,
					Usage: "WebSocket CORS origin (can be specified multiple times).",
				},
			),
		},
	}

	return app
}
1087964
func NewModule(name string) *Module {
	return &Module{
		Name:   name,
		Flags:  []cli.Flag{},
		Depend: Modules{},
	}
}
411294
func New() *Application {
	app := new(Application)
	app.router = newRouter()
	app.staticRouter = make(map[string][]string)
	app.View = NewView()
	app.Config = NewConfig()
	app.errorHandler = make(map[int]ErrorHandlerFunc)
	app.middlewareChain = NewChain()
	app.DefaultErrorHandler = defaultErrorHandler
	app.pool.New = func() interface{} {
		return new(Context)
	}
	app.handlerChain = app.middlewareChain.Final(app.handler)
	return app
}
16455
func New(appName, appOwner string, cfgs ...Configurator) *Bootstrapper {
	b := &Bootstrapper{
		AppName:      appName,
		AppOwner:     appOwner,
		AppSpawnDate: time.Now(),
		Application:  iris.New(),
	}

	for _, cfg := range cfgs {
		cfg(b)
	}

	return b
}
734342
func (client *Client) CreateApplication(app Application) (Application, Warnings, error) {
	body, err := json.Marshal(app)
	if err != nil {
		return Application{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostAppRequest,
		Body:        bytes.NewReader(body),
	})
	if err != nil {
		return Application{}, nil, err
	}

	var updatedApp Application
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &updatedApp,
	}

	err = client.connection.Make(request, &response)
	return updatedApp, response.Warnings, err
}
244187
func NewAppCmd(binPath string, port int, runMode string, paths *model.RevelContainer) AppCmd {
	cmd := exec.Command(binPath,
		fmt.Sprintf("-port=%d", port),
		fmt.Sprintf("-importPath=%s", paths.ImportPath),
		fmt.Sprintf("-runMode=%s", runMode))
	cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
	return AppCmd{cmd}
}
575726
func NewGoatApp(name, version, basePath string) (app.App, error) {
	gapp := &GoatApp{
		name:    name,
		version: version,
	}

	if err := gapp.initEngineScope(); err != nil {
		return nil, err
	}
	if err := gapp.initArgsScope(); err != nil {
		return nil, err
	}
	if err := gapp.initFilespaceScope(basePath); err != nil {
		return nil, err
	}
	if err := gapp.initConfigScope(); err != nil {
		return nil, err
	}
	if err := gapp.initDependencyScope(); err != nil {
		return nil, err
	}
	if err := gapp.initAppScope(); err != nil {
		return nil, err
	}
	if err := gapp.initCommandScope(); err != nil {
		return nil, err
	}

	gapp.dp.SetDefault(app.EngineScope, gapp.engineScope)
	gapp.dp.SetDefault(app.ArgsScope, gapp.argsScope)
	gapp.dp.SetDefault(app.FilespaceScope, gapp.filespaceScope)
	gapp.dp.SetDefault(app.ConfigScope, gapp.configScope)
	gapp.dp.SetDefault(app.DependencyScope, gapp.dependencyScope)
	gapp.dp.SetDefault(app.AppScope, gapp.appScope)
	gapp.dp.SetDefault(app.CommandScope, gapp.commandScope)

	gapp.dp.SetDefault(app.InputService, gio.NewAppInput(os.Stdin))
	gapp.dp.SetDefault(app.OutputService, gio.NewAppOutput(os.Stdout))

	gapp.dp.AddInjectors([]dependency.Injector{
		gapp.commandScope,
		gapp.appScope,
		// gapp.dependencyScope, <- it is wraper for dependency injection and musn't
		// contains recursive injection
		gapp.configScope,
		gapp.filespaceScope,
		gapp.argsScope,
		gapp.engineScope,
	})

	return gapp, nil
}
598074
func New(c *client.Client, id string) (api.App, error) {
	body := []byte{}

	var err error
	if id != "" {
		req := api.AppCreateRequest{ID: id}
		body, err = json.Marshal(req)

		if err != nil {
			return api.App{}, err
		}
	}

	resBody, err := c.BasicRequest("POST", "/v1/apps/", body)

	if err != nil {
		return api.App{}, err
	}

	app := api.App{}
	if err = json.Unmarshal([]byte(resBody), &app); err != nil {
		return api.App{}, err
	}

	return app, nil
}
1309781
func start() {
	fmt.Printf("Starting %s...", AppName)
	if err := Start(1); err != nil {
		failed(err)
	} else {
		fmt.Println("OK")
	}
}
1297755
func NewKsonnetApp(path string) (KsonnetApp, error) {
	ksApp := ksonnetApp{rootDir: path}
	// ensure that the file exists
	if _, err := ksApp.appYamlPath(); err != nil {
		return nil, err
	}
	return &ksApp, nil
}