From bb2f7788f6bfb3ec32b10a7dd7dbdd5acf909cf3 Mon Sep 17 00:00:00 2001 From: ajatprabha Date: Sun, 3 Oct 2021 07:34:21 +0530 Subject: [PATCH] add usage documentation --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ example_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 example_test.go diff --git a/README.md b/README.md index 27968de..cd58e5c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,54 @@ To build Docker image locally, run: make docker ``` +### Importing into projects + +You can import `asynqmon` into other projects and create a single binary to serve other components of `asynq` and `asynqmon` from a single binary. + +
Example +

+ +> `staticContents` can be embedded by using the pre-built UI bundle from the Releases section. + +```go +package main + +import ( + "embed" + "log" + "net/http" + + "github.com/hibiken/asynq" + "github.com/hibiken/asynqmon" +) + +//go:embed ui-assets/* +var staticContents embed.FS + +func main() { + api := asynqmon.NewAPI(asynqmon.APIOptions{ + RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, + StaticContentHandler: asynqmon.NewStaticContentHandler( + staticContents, + "ui-assets", + "index.html", + ), + }) + defer api.Close() + + srv := &http.Server{ + Handler: api, + Addr: ":8080", + } + + log.Fatal(srv.ListenAndServe()) +} +``` + +

+
+ + ## Run To use the defaults, simply run and open http://localhost:8080. diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..058cd04 --- /dev/null +++ b/example_test.go @@ -0,0 +1,32 @@ +package asynqmon_test + +import ( + "embed" + "log" + "net/http" + + "github.com/hibiken/asynq" + "github.com/hibiken/asynqmon" +) + +//go:embed ui-assets/* +var staticContents embed.FS + +func ExampleNewAPI() { + api := asynqmon.NewAPI(asynqmon.APIOptions{ + RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, + StaticContentHandler: asynqmon.NewStaticContentHandler( + staticContents, + "ui-assets", + "index.html", + ), + }) + defer api.Close() + + srv := &http.Server{ + Handler: api, + Addr: ":8080", + } + + log.Fatal(srv.ListenAndServe()) +}