add usage documentation

This commit is contained in:
ajatprabha 2021-10-03 07:34:21 +05:30 committed by Ken Hibino
parent e04ec62920
commit bb2f7788f6
2 changed files with 80 additions and 0 deletions

View File

@ -47,6 +47,54 @@ To build Docker image locally, run:
make docker 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.
<details><summary>Example</summary>
<p>
> `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())
}
```
</p>
</details>
## Run ## Run
To use the defaults, simply run and open http://localhost:8080. To use the defaults, simply run and open http://localhost:8080.

32
example_test.go Normal file
View File

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