melodywen / go-box

go box tool lib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-box

Build Status Go Report Card GoDoc license

Overview

This project builds the necessary components such as configuration files, service providers, middleware, Facades, and so on. The specific implementation is to refer to laravel framework implementation;

done:

  • Configuration file
  • Service provider
  • Event dispatcher
  • Overall improvement of the framework of application

todo:

  • Exception handling
  • facades
  • middleware

example

config/services.go

// EagerServices eager services
var EagerServices []support.ServiceProviderInterface

// DeferServices defer services
var DeferServices map[string]support.ServiceProviderInterface

func init() {
	EagerServices = []support.ServiceProviderInterface{
		providers.NewSchoolServiceProvider(),
	}
	DeferServices = map[string]support.ServiceProviderInterface{
		"teacher": providers.NewTeacherServiceProvider(),
		"student": providers.NewStudentServiceProvider(),
	}
}

app.go

 // App construction app instance
var App foundation.ApplicationInterface

// init App
func init() {
	dir, _ := os.Getwd()

	app := foundation2.NewApplication(dir)
	app.Instance("eager-services", config.EagerServices)
	app.Instance("defer-services", config.DeferServices)

	App = app
	app.BootstrapOpenListen()
	var httpKernel http.KernelInterface
	App.Singleton(&httpKernel, http2.NewKernel)
}

main.go

func main() {
	var httpKernel http.KernelInterface
	var ok bool
	k := App.Make(&httpKernel)

	if httpKernel, ok = k.(http.KernelInterface); !ok {
		logrus.Panicln("获取 http kernel 失败")
	}

	httpKernel.Handle()

	App.Make("school")
	fmt.Println(httpKernel)
}

About

go box tool lib

License:MIT License


Languages

Language:Go 100.0%