From bd61d05208771500a7f7d7eda12edbcbe7ba92ed Mon Sep 17 00:00:00 2001
From: Pulkit Kathuria
Date: Fri, 22 Dec 2023 22:31:41 +0900
Subject: [PATCH] (docs) README displays examples and API docs
---
.github/workflows/build.yml | 2 +-
.github/workflows/coveritup.yml | 29 ++++++++
.github/workflows/test.yml | 4 +-
README.md | 120 +++++++++++++++++++++++---------
pkg/echo.go | 1 +
pkg/line_chart_handler_test.go | 2 +-
6 files changed, 120 insertions(+), 38 deletions(-)
create mode 100644 .github/workflows/coveritup.yml
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 1443e74..ec814e6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,5 +1,5 @@
on:
- pull_request:
+ push:
paths:
- '**/*.go'
- '**/*.mod'
diff --git a/.github/workflows/coveritup.yml b/.github/workflows/coveritup.yml
new file mode 100644
index 0000000..695b453
--- /dev/null
+++ b/.github/workflows/coveritup.yml
@@ -0,0 +1,29 @@
+on:
+ push:
+ paths:
+ - '**/*.go'
+ - '**/*.mod'
+ - '**/*.sum'
+ - '**/*.yaml'
+name: CI
+jobs:
+ test:
+ strategy:
+ matrix:
+ go-version: [dev-latest]
+ os: [ubuntu-latest, macos-latest]
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: kevincobain2000/action-gobrew@v2
+ with:
+ version: ${{ matrix.go-version }}
+ - name: Install Tools
+ run: |
+ go install github.com/securego/gosec/v2/cmd/gosec@latest
+ go install github.com/axw/gocov/gocov@latest
+ go install github.com/AlekSi/gocov-xml@latest
+ - name: Lint
+ run: |
+ gosec ./...
+ go vet -all .
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index ae27426..4717b59 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,5 +1,5 @@
on:
- pull_request:
+ push:
paths:
- '**/*.go'
- '**/*.mod'
@@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- - uses: kevincobain2000/action-gobrew@v2.2
+ - uses: kevincobain2000/action-gobrew@v2
with:
version: ${{ matrix.go-version }}
- name: Test
diff --git a/README.md b/README.md
index 5c3299a..def7742 100644
--- a/README.md
+++ b/README.md
@@ -4,16 +4,10 @@
- Chart to Image API interface for go-charts.
-
- Data Driven READMEs.
-
-
-
-
+ Chart as Image - API using go-charts.
-**Quick Setup:** Easy setup. Add charts to your README.
+**Quick Setup:** Easy setup. Add charts as images in markdown, emails etc.
**Hassle Free:** Create charts as images with single URL.
@@ -22,58 +16,116 @@
# Build Status
-## Development
+# API
+
+`https://instachart.coveritup.app`
+
+## `GET /line`
+
+| Query Param | Required | Description | Example |
+| :---------- | :------- | :---------- | :------------------------------------------------------------------------ |
+| `data` | ◯ | JSON | `?data={ "x": [["2022-12-23","2022-12-24","2023-12-25"]],"y": [[1,2,3]]}` |
+| `title` | | string | |
+| `x_label` | | string | |
+| `y_label` | | string | |
+| `height` | | int | |
+| `width` | | int | |
-```sh
-air
-```
-## API Docs
+| `data` | Required | Description | Example |
+| :------ | :------- | :---------- | :------------------------------------ |
+| `x` | ◯ | []Array | `"x": [["2022-12-23","2022-12-24"], ` |
+| `y` | ◯ | []Array | `"y": [[1,2,3],[3,5,7]]` |
+| `names` | | Array | `"names": ["Series A", "Series B"]` |
-### Line Chart
+### Single Line Series
-#### Single date series
+
+ Image URL
```sh
-http://localhost:3000/line?data={
+https://instachart.coveritup.app/line?title=Line+single+Series&x_label=dates&y_label=amount&data={
"x": [["2022-12-23","2022-12-24","2023-12-25"]],
"y": [[1,2,3]]
}
```
+
-#### Multiple date series
+---
+
+![Line single series](https://instachart.coveritup.app/line?title=Line+single+Series&x_label=dates&y_label=amount&data={%20%22x%22:%20[[%222022-12-23%22,%222022-12-24%22,%222023-12-25%22]],%20%22y%22:%20[[1,2,3]],%20%22names%22:%20[%22Series%20A%22]%20})
+
+### Multiple Line Series
+
+
+ Image URL
```sh
-http://localhost:3000/line?data={
+https://instachart.coveritup.app/line??title=Multi+Line+Series&x_label=dates&y_label=amount&data={
"x": [["2022-12-23","2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"]],
- "y": [[1,2,3], [2,5,3]]
+ "y": [[1,2,3], [1,5,10]],
+ "names": ["Series A", "Series B"]
}
```
+
+
+---
+
+![Multi line series](https://instachart.coveritup.app/line?title=Multi+Line+Series&x_label=dates&y_label=amount&data={%20%22x%22:%20[[%222022-12-23%22,%222022-12-24%22,%222023-12-25%22],%20[%222022-12-23%22,%222022-12-28%22,%222023-12-30%22]],%20%22y%22:%20[[1,2,3],%20[1,5,10]],%20%22names%22:%20[%22Series%20A%22,%20%22Series%20B%22]%20})
+
+
+### Continuous Series
-#### Continuous Series
+
+ Image URL
```sh
-http://localhost:3000/line?data={
- "x": [["10","20","30"]],
- "y": [[1,2,3]]
+https://instachart.coveritup.app/line??title=Continuous+Series&x_label=No+of+people&y_label=amount&data={
+ "x": [["10","20","30"], ["10","20","30"], ["10","20","30"]],
+ "y": [[1,2,3], [10,20,30], [6,3,9]],
+ "names": ["Series A", "Series B", "Series C"]
}
```
-#### Multiple Continuous Series
+
+
+---
+
+![Multi line series](https://instachart.coveritup.app/line?title=Continuous+Series&x_label=No+of+people&y_label=amount&data={%20"x":%20[["10","20","30"],%20["10","20","30"],%20["10","20","30"]],%20"y":%20[[1,2,3],%20[10,20,30],%20[6,3,9]]%20})
+
+
+
+## `GET /bar`
+
+| Query Param | Required | Description | Example |
+| :---------- | :------- | :---------- | :--------------------------------------------------- |
+| `data` | ◯ | JSON | `?data={ "x": [["Mon","Tue","Wed"]],"y": [[1,2,3]]}` |
+| `title` | | string | |
+| `y_label` | | string | |
+| `height` | | int | |
+| `width` | | int | |
+
+
+| `data` | Required | Description | Example |
+| :------ | :------- | :---------- | :------------------------------------ |
+| `x` | ◯ | []Array | `"x": [["Mon","Tue", "Wed"], ` |
+| `y` | ◯ | []Array | `"y": [[1,2,3]]` |
+
+
+### Series
+
+
+ Image URL
```sh
-http://localhost:3000/line?data={
- "x": [["10","20","30"], ["10","20","30"]],
- "y": [[1,2,3], [10,20,30]]
+https://instachart.coveritup.app/bar?title=Bar+Chart&y_label=Sleeping+hours&data={
+ "x": ["Monday", "Friday", "Sunday"],
+ "y": [8, 2 ,14]
}
```
-### Bar Chart
+
-#### Series
+---
-```sh
-http://localhost:3000/bar?title=sleeping+hours
-&y_label=hours
-&data={ "x": ["Monday","Sunday"], "y": [8, 14] }
-```
\ No newline at end of file
+![Bar chart](https://instachart.coveritup.app/bar?title=Bar+Chart&y_label=Sleeping+hours&data={%20%22x%22:%20[%22Monday%22,%20%22Friday%22,%20%22Sunday%22],%20%22y%22:%20[8,%202%20,14]%20})
\ No newline at end of file
diff --git a/pkg/echo.go b/pkg/echo.go
index 8872874..d330f96 100644
--- a/pkg/echo.go
+++ b/pkg/echo.go
@@ -15,6 +15,7 @@ import (
func NewEcho() *echo.Echo {
e := echo.New()
e.HTTPErrorHandler = HTTPErrorHandler
+ e.Pre(middleware.RemoveTrailingSlash())
SetupLogger(e)
SetupRoutes(e)
return e
diff --git a/pkg/line_chart_handler_test.go b/pkg/line_chart_handler_test.go
index 06d392b..743cd9b 100644
--- a/pkg/line_chart_handler_test.go
+++ b/pkg/line_chart_handler_test.go
@@ -14,7 +14,7 @@ func TestGetLineRequestChart_ValidRequest(t *testing.T) {
e := echo.New()
e.GET("/line", func(c echo.Context) error {
- img, err := NewLineChartHandler().GetLineRequestChart(c)
+ img, err := NewLineChartHandler().Get(c)
if err != nil {
return err
}