mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 03:05:53 +08:00
add usage documentation
This commit is contained in:
parent
e04ec62920
commit
bb2f7788f6
48
README.md
48
README.md
@ -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
32
example_test.go
Normal 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())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user