コード例 #1
0
ファイル: app.go プロジェクト: ts33kr/boot
// Create and initialize a new application. This is a front gate for
// the framework, since you should start by creating a new app struct.
// Every application should have a valid name (tag) and a version. So
// this function makes sure they have been passed and are all valid.
// Generally, you should not be creating more than one application.
func New(name, version string) *App {
	var room = make(map[string]interface{})
	const url = "https://github.com/ts33kr/boot"
	const ename = "name is not of correct format"
	const eversion = "version is not valid semver"
	pattern := regexp.MustCompile("^[a-zA-Z0-9-_]+$")
	var parsed semver.Version = semver.MustParse(version)
	if !pattern.MatchString(name) {
		panic(ename)
	}
	if parsed.Validate() != nil {
		panic(eversion)
	}
	application := &App{Name: name, Version: parsed}
	application.Storage = Storage{Container: room}
	application.CronEngine = cron.New() // create CRON
	application.Servers = make(map[string]*http.Server)
	application.Reference = shortuuid.New() // V4
	application.Providers = make([]*Provider, 0)
	application.Services = make([]*Service, 0)
	application.TimeLayout = time.RFC850
	application.Namespace = url // set
	return application          // prepared app
}