Skip to content

Commit f83c0ba

Browse files
committed
initial commit
1 parent 0beb45f commit f83c0ba

File tree

13 files changed

+637
-0
lines changed

13 files changed

+637
-0
lines changed

.github/workflows/release.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build and release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Log in to the Container registry
16+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
17+
with:
18+
registry: ${{ env.REGISTRY }}
19+
username: ${{ github.actor }}
20+
password: ${{ secrets.GITHUB_TOKEN }}
21+
- name: Set up Go
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: '~1.20'
25+
id: go
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v1
28+
- name: Set up Docker Buildx
29+
id: buildx
30+
uses: docker/setup-buildx-action@v1
31+
- name: Check out code into the Go module directory
32+
uses: actions/checkout@v2
33+
with:
34+
lfs: true
35+
fetch-depth: 0
36+
- name: Checkout LFS objects
37+
run: git lfs checkout
38+
- name: Pull tag
39+
run: git fetch --tags
40+
- name: Run GoReleaser
41+
uses: goreleaser/goreleaser-action@v4
42+
with:
43+
version: latest
44+
args: release --rm-dist
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.idea
3+
/notes
4+
/dist
5+
/build

.goreleaser.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
builds:
2+
- env:
3+
- CGO_ENABLED=0
4+
goos:
5+
- linux
6+
- darwin
7+
- windows
8+
flags:
9+
- -trimpath
10+
goarch:
11+
- arm64
12+
- amd64
13+
main: ./cmd/api-notes/main.go
14+
binary: api-notes
15+
checksum:
16+
name_template: 'checksums.txt'
17+
snapshot:
18+
name_template: "{{ incpatch .Version }}-next"
19+
dockers:
20+
- image_templates:
21+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-amd64"
22+
use: buildx
23+
dockerfile: Dockerfile
24+
build_flag_templates:
25+
- "--platform=linux/amd64"
26+
- image_templates:
27+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-arm64v8"
28+
use: buildx
29+
goarch: arm64
30+
dockerfile: Dockerfile
31+
build_flag_templates:
32+
- "--platform=linux/arm64/v8"
33+
docker_manifests:
34+
- name_template: "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}"
35+
image_templates:
36+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-amd64"
37+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-arm64v8"
38+
# alias for latest
39+
- name_template: "ghcr.io/reddec/{{ .ProjectName }}:latest"
40+
image_templates:
41+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-amd64"
42+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-arm64v8"
43+
# alias for major version (x)
44+
- name_template: "ghcr.io/reddec/{{ .ProjectName }}:{{.Major}}"
45+
image_templates:
46+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-amd64"
47+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-arm64v8"
48+
# alias for minor version (x.y)
49+
- name_template: "ghcr.io/reddec/{{ .ProjectName }}:{{.Major}}.{{.Minor}}"
50+
image_templates:
51+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-amd64"
52+
- "ghcr.io/reddec/{{ .ProjectName }}:{{ .Version }}-arm64v8"
53+
changelog:
54+
sort: asc
55+
filters:
56+
exclude:
57+
- '^docs:'
58+
- '^test:'

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM scratch
2+
# 8080 for API
3+
EXPOSE 8080/tcp
4+
VOLUME /data
5+
ENV BIND=":8080" \
6+
PUBLIC_URL="http://127.0.0.1:8081" \
7+
DIR="/data"
8+
ENTRYPOINT ["/api-notes"]
9+
ADD api-notes /

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# API-Notes
2+
3+
Dead simple service for publishing notes via API. Markdown supported.
4+
5+
The service exposes minimal API for upload markdown (with attachments) and render it as HTML.
6+
7+
The generated link is 16-bytes randomly generated and can be shared relatively safely.
8+
9+
The API-Notes is NOT serving notes - any reverse proxy must do it. With authorization if needed.
10+
See [docker-compose.yaml].
11+
12+
Supported markdown extensions:
13+
14+
- GFM (GitHub Flavored Markdown)
15+
- Footnotes
16+
- Basic syntax highlighting
17+
- Mermaid
18+
- MathJax
19+
- Embedded youtube
20+
21+
## Installation
22+
23+
- Docker: `ghcr.io/reddec/api-notes:latest`
24+
- Go: `go install github.com/reddec/api-notes/cmd/...@latest`
25+
26+
## Configuration
27+
28+
| Environment variable | Default | Description |
29+
|----------------------|-------------------------|------------------------------|
30+
| `PUBLIC_URL` | `http://127.0.0.1:8080` | Public URL to where redirect |
31+
| `BIND` | `127.0.0.1:8080` | Binding address |
32+
| `DIR` | `notes` | Directory for notes |
33+
34+
Differences in docker version
35+
36+
| Environment variable | Default | Description |
37+
|----------------------|----------------|---------------------|
38+
| `BIND` | `0.0.0.0:8080` | Binding address |
39+
| `DIR` | `/data` | Directory for notes |
40+
41+
## API
42+
43+
Supported content type:
44+
45+
- `application/json`: only `title` (string) and `text` (string) supported
46+
- `application/x-www-form-urlencoded`: only `title` and `text` field supported
47+
- `multipart/form-data`: `title`, `text` and any file(s) supported
48+
49+
> Note: note ID should not be escaped
50+
51+
### Create note
52+
53+
POST /note
54+
55+
Returns `303 See Other` with public link in header `Location`, and ID in `X-Correlation-Id`.
56+
57+
**Example**
58+
59+
Create with basic form
60+
61+
curl -v -d 'title=hello&text=this is text' http://127.0.0.1:8080/note
62+
63+
Create with JSON
64+
65+
curl -v -H 'Content-Type: application/json' --data-binary '{"title": "hello", "text": "this is text"}' http://127.0.0.1:8080/note
66+
67+
Create with attachments
68+
69+
curl -v -F title=hello -F text="this is text" -F file1=@file1 -F file2=@file2 http://127.0.0.1:8080/note
70+
71+
### Update note
72+
73+
PUT /note/{note ID}
74+
75+
Returns `303 See Other` with public link (old) in header `Location`.
76+
77+
**Example**
78+
79+
Update note (id: `b6/22/7f/2ce9505bef907fa98075f852b6`) with basic form
80+
81+
curl -X PUT -v -d 'title=hello&text=this is another text' http://127.0.0.1:8080/note/b6/22/7f/2ce9505bef907fa98075f852b6
82+
83+
### Delete note
84+
85+
DELETE /note/{note ID}
86+
87+
Returns `204 No Content`
88+
89+
**Example**
90+
91+
Delete note (id: `b6/22/7f/2ce9505bef907fa98075f852b6`)
92+
93+
curl -X DELETE -v http://127.0.0.1:8080/note/b6/22/7f/2ce9505bef907fa98075f852b6

0 commit comments

Comments
 (0)