Skip to content

An unofficial Nginx Unit SDK for Go.

License

Notifications You must be signed in to change notification settings

peknur/nginx-unit-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx Unit SDK

Test Go Reference

An unofficial Nginx Unit SDK for Go.
SDK is in alpha state and breaking changes might occur. Tested against Nginx Unit v1.28.

From the Nginx Unit authors:
NGINX Unit is a dynamic application server, capable of running beside NGINX Plus and NGINX Open Source or standalone. NGINX Unit supports a RESTful JSON API, deploys configuration changes without service disruptions, and runs apps built with multiple languages and frameworks. Designed from scratch around the needs of your distributed applications, it lays the foundation for your.

Nginx Unit developer documentation

Install

$ go get github.com/peknur/nginx-unit-sdk

Example

svc, err := unit.NewServiceFromURL("http://127.0.0.1:8080")
if err != nil {
	log.Fatal(err)
}
cfg := config.Config{
	Listeners: config.Listeners{
		"*:80": listener.Config{
			Pass: "routes/main",
		},
	},
	Routes: config.Routes{
		"main": []route.Config{
			{
				Action: &route.Action{
					Pass: "applications/go",
				},
			}},
	},
	Applications: config.Applications{
		"go": application.Config{
			Type:             application.TypeGo,
			Executable:       "app",
			WorkingDirectory: "/apps/go",
			User:             "www-data",
			Group:            "www-data",
		},
	},
	AccessLog: {
		Path: "/var/log/unit.log",
	}
}

if err := svc.CreateConfig(context.Background(), cfg); err != nil {
	log.Fatal(err)
}