Example #1
0
File: main.go Project: yunhor/iris
func init() {

	// set the current working dir
	if d, err := os.Getwd(); err != nil {
		panic(err)
	} else {
		workingDir = d
	}

	// init the cli app
	app = cli.NewApp("iris", "Command line tool for Iris web framework", Version)
	// version command
	app.Command(cli.Command("version", "\t      prints your iris version").Action(func(cli.Flags) error { app.Printf("%s", iris.Version); return nil }))

	// create command/-/create.go
	createCmd := cli.Command("create", "create a project to a given directory").
		Flag("offline", false, "set to true to disable the packages download on each create command").
		Flag("dir", workingDir, "$GOPATH/src/$dir the directory to install the sample package").
		Flag("type", "basic", "creates a project based on the -t package. Currently, available types are 'basic' & 'static'").
		Action(create)

	// run command/-/run.go
	runAndWatchCmd := cli.Command("run", "runs and reload on source code changes, example: iris run main.go").Action(runAndWatch)

	// register the commands
	app.Command(createCmd)
	app.Command(runAndWatchCmd)

	// init the logger
	printer = logger.New(config.DefaultLogger())
}
Example #2
0
// New returns the logger middleware as HandlerFunc with the default settings if second parameter is not passed
func New(theLogger *logger.Logger, options ...Options) iris.HandlerFunc {
	if theLogger == nil {
		theLogger = logger.New(config.DefaultLogger())
	}

	l := &loggerMiddleware{Logger: theLogger}

	if len(options) > 0 {
		l.options = options[0]
	} else {
		l.options = DefaultOptions()
	}

	return l.Serve
}
Example #3
0
// New creates and returns a new Iris station aka Framework.
//
// Receives an optional config.Iris as parameter
// If empty then config.Default() is used instead
func New(cfg ...config.Iris) *Framework {
	c := config.Default().Merge(cfg)

	// we always use 's' no 'f' because 's' is easier for me to remember because of 'station'
	// some things never change :)
	s := &Framework{Config: &c}
	{
		///NOTE: set all with s.Config pointer
		// set the Logger
		s.Logger = logger.New(s.Config.Logger)
		// set the plugin container
		s.Plugins = &pluginContainer{logger: s.Logger}
		// set the websocket server
		s.Websocket = websocket.NewServer(s.Config.Websocket)
		// set the servemux, which will provide us the public API also, with its context pool
		mux := newServeMux(sync.Pool{New: func() interface{} { return &Context{framework: s} }}, s.Logger)
		// set the public router API (and party)
		s.muxAPI = &muxAPI{mux: mux, relativePath: "/"}
		// set the server
		s.HTTPServer = newServer(&s.Config.Server)
	}

	return s
}