示例#1
0
文件: api.go 项目: jonasi/project
	"github.com/jonasi/mohttp/hateoas"
	"github.com/jonasi/project/server/api"
	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/load"
	"github.com/shirou/gopsutil/process"
	"golang.org/x/net/context"
)

var apiService = hateoas.NewService(
	hateoas.ServiceUse(api.JSON),
	hateoas.AddResource(root, cpuRsc, loadRsc, procRsc),
)

var root = hateoas.NewResource(
	hateoas.Path("/"),
	hateoas.AddLink("cpus", cpuRsc),
	hateoas.AddLink("load", loadRsc),
	hateoas.AddLink("processes", procRsc),
	hateoas.HEAD(mohttp.EmptyBodyHandler),
)

var cpuRsc = hateoas.NewResource(
	hateoas.Path("/cpus"),
	hateoas.GET(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
		return cpu.CPUInfo()
	})),
)

var loadRsc = hateoas.NewResource(
	hateoas.Path("/load"),
	hateoas.GET(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
示例#2
0
文件: api.go 项目: jonasi/project
)

var setSrv, getSrv = mohttp.ContextValueAccessors("github.com/jonasi/project/server.Server")

func getServer(c context.Context) *Server {
	return getSrv(c).(*Server)
}

var apiService = hateoas.NewService(
	hateoas.AddResource(root, version, status, plugins),
	hateoas.ServiceUse(api.JSON, api.AddLinkHeaders),
)

var root = hateoas.NewResource(
	hateoas.Path("/"),
	hateoas.AddLink("version", version),
	hateoas.AddLink("status", status),
	hateoas.AddLink("plugins", plugins),
	hateoas.HEAD(mohttp.EmptyBodyHandler),
)

var version = hateoas.NewResource(
	hateoas.Path("/version"),
	hateoas.GET(mohttp.StaticDataHandler(Version)),
)

var status = hateoas.NewResource(
	hateoas.Path("/status"),
	hateoas.PATCH(mohttp.HandlerFunc(func(c context.Context) {
		var body struct {
			Status string `json:"status"`
示例#3
0
文件: api.go 项目: jonasi/project
)

var apiService = hateoas.NewService(
	hateoas.ServiceUse(api.JSON),
	hateoas.AddResource(
		root,
		commands,
		command,
		stdout,
		stderr,
	),
)

var root = hateoas.NewResource(
	hateoas.Path("/"),
	hateoas.AddLink("commands", commands),
)

var commands = hateoas.NewResource(
	hateoas.Path("/commands"),
	hateoas.GET(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
		commander := getCommander(c)
		return commander.History(), nil
	})),
	hateoas.POST(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
		var (
			logger    = plugin.GetLogger(c)
			commander = getCommander(c)
		)

		var args struct {
示例#4
0
文件: api.go 项目: jonasi/project
	hateoas.AddResource(
		root,
		version,
		config,
		env,
		formulae,
		installed,
		installedFormula,
		formula,
		search,
	),
)

var root = hateoas.NewResource(
	hateoas.Path("/"),
	hateoas.AddLink("version", version),
	hateoas.AddLink("formulae", formulae),
)

var version = hateoas.NewResource(
	hateoas.Path("/version"),
	hateoas.GET(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
		return getBrew(c).Version()
	})),
)

var config = hateoas.NewResource(
	hateoas.Path("/config"),
	hateoas.GET(mohttp.DataHandlerFunc(func(c context.Context) (interface{}, error) {
		return getBrew(c).Config()
	})),