Gin: add gin into the framework
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
[submodule "framework/gin"]
 | 
			
		||||
	path = framework/gin
 | 
			
		||||
	url = gitea@git.vinchent.xyz:vinchent/gin.git
 | 
			
		||||
@ -18,16 +18,14 @@ type Container interface {
 | 
			
		||||
	// IsBound returns true the provider is bound to the container.
 | 
			
		||||
	IsBound(name string) bool
 | 
			
		||||
 | 
			
		||||
	// Get gets or creates a service by its name.
 | 
			
		||||
	// Make gets or creates a service by its name.
 | 
			
		||||
	//
 | 
			
		||||
	// Return error if the service cannot be initiated or doesn't exist.
 | 
			
		||||
	Get(name string) (interface{}, error)
 | 
			
		||||
	Make(name string) (interface{}, error)
 | 
			
		||||
 | 
			
		||||
	// JustGet gets a service, return nil if error.
 | 
			
		||||
	JustGet(name string) interface{}
 | 
			
		||||
 | 
			
		||||
	// GetExisted gets an initiated service by its name.
 | 
			
		||||
	GetExisted(name string) interface{}
 | 
			
		||||
	// MustMake makes a service, supposing that it is not instantiated before.
 | 
			
		||||
	// Return nil if error.
 | 
			
		||||
	MustMake(name string) interface{}
 | 
			
		||||
 | 
			
		||||
	// MakeNew creates a new instance of the service with different parameters.
 | 
			
		||||
	//
 | 
			
		||||
@ -109,15 +107,11 @@ func (c *GoWebContainer) getServiceProvider(name string) ServiceProvider {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GoWebContainer) Get(name string) (interface{}, error) {
 | 
			
		||||
func (c *GoWebContainer) Make(name string) (interface{}, error) {
 | 
			
		||||
	return c.makeServiceInstance(name, nil, false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GoWebContainer) GetExisted(name string) interface{} {
 | 
			
		||||
	return c.getServiceInstance(name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GoWebContainer) JustGet(name string) interface{} {
 | 
			
		||||
func (c *GoWebContainer) MustMake(name string) interface{} {
 | 
			
		||||
	ins, err := c.makeServiceInstance(name, nil, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil
 | 
			
		||||
 | 
			
		||||
@ -75,7 +75,7 @@ func TestBind(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	container.Bind(provider)
 | 
			
		||||
 | 
			
		||||
	dummyService := container.JustGet(DummyProviderName).(IDummyService)
 | 
			
		||||
	dummyService := container.MustMake(DummyProviderName).(IDummyService)
 | 
			
		||||
 | 
			
		||||
	want := DummyStruct{
 | 
			
		||||
		Name: "Dummy!",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								framework/gin
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								framework/gin
									
									
									
									
									
										Submodule
									
								
							 Submodule framework/gin added at f05f966a08
									
								
							
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@ -35,3 +35,5 @@ require (
 | 
			
		||||
	gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
 | 
			
		||||
	gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
replace github.com/gin-gonic/gin => ./framework/gin
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								main.go
									
									
									
									
									
								
							@ -10,19 +10,11 @@ import (
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"git.vinchent.xyz/vinchent/go-web/framework"
 | 
			
		||||
	"git.vinchent.xyz/vinchent/go-web/providers/webserver"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	container := framework.NewGoWebContainer()
 | 
			
		||||
	webServiceProvider := &webserver.WebSrvProvider{}
 | 
			
		||||
 | 
			
		||||
	container.Bind(webServiceProvider)
 | 
			
		||||
 | 
			
		||||
	goWebGin := container.JustGet(webserver.WebSrvName).(*webserver.GoWebGin)
 | 
			
		||||
 | 
			
		||||
	core := goWebGin.Engine
 | 
			
		||||
	core := gin.New()
 | 
			
		||||
	registerRouter(core)
 | 
			
		||||
	server := &http.Server{
 | 
			
		||||
		Addr:    ":8080",
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user