Skip to content

Latest commit

 

History

History
55 lines (49 loc) · 1.73 KB

README.md

File metadata and controls

55 lines (49 loc) · 1.73 KB

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)
}