Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 20c60a4

Browse files
authored
Merge pull request #3 from Kovah/go-rewrite
Rewrite in Go
2 parents da5c37a + 1be0590 commit 20c60a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3690
-686
lines changed

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test with Go
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v1
16+
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.14
20+
21+
- name: Install required packages
22+
run: go mod download
23+
24+
- name: Link main repo as package
25+
run: |
26+
mkdir -p /home/runner/go/src/github.com/Kovah
27+
ln -s /home/runner/work/DevLorem/DevLorem /home/runner/go/src/github.com/Kovah/DevLorem
28+
29+
- name: Build and test with Go
30+
run: go test -run ''

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dist
2+
/node_modules
3+
rice-box.go
4+
DevLorem

.goreleaser.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
project_name: devlorem
2+
3+
before:
4+
hooks:
5+
- go mod download
6+
- go get github.com/GeertJohan/go.rice
7+
- rice -v embed-go
8+
9+
builds:
10+
-
11+
id: devlorem
12+
binary: devlorem
13+
env:
14+
- CGO_ENABLED=0
15+
goos:
16+
- darwin
17+
- linux
18+
- windows
19+
- freebsd
20+
- netbsd
21+
- openbsd
22+
- dragonfly
23+
goarch:
24+
- amd64
25+
- 386
26+
- arm
27+
- arm64
28+
goarm:
29+
- 7
30+
31+
archives:
32+
-
33+
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
34+
replacements:
35+
darwin: Darwin
36+
linux: Linux
37+
windows: Windows
38+
386: i386
39+
amd64: x86_64
40+
files:
41+
- README.md
42+
- LICENSE.md
43+
44+
checksum:
45+
name_template: checksums.txt
46+
47+
snapshot:
48+
name_template: "{{.Tag}}"
49+
50+
dockers:
51+
- image_templates:
52+
- "kovah/devlorem:latest"
53+
- "kovah/devlorem:{{.Version}}"
54+
55+
changelog:
56+
sort: asc

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:latest
2+
COPY devlorem /
3+
ENTRYPOINT ["/devlorem"]

README.md

Lines changed: 160 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,180 @@
1-
# DevLorem
1+
<h1 align="center">DevLorem</h1>
22

3-
Show paragraphs of real text ready to copy and paste. No more "Lorem ipsum dolor", get some lines from President Obama,
4-
Jim Carrey or Morgan Freeman.
3+
<p align="center"><b>Real quotes ready to copy and paste. No more "Lorem ipsum dolor".</b><br>Get some quotes from President Obama,
4+
Samuel L Jackson, Daisy Ridley or Morgan Freeman!</p>
55

6-
![Preview Screenshot](/preview.png)
6+
<p>&nbsp;</p>
77

8-
## Get Quotes via API
8+
<img src="/preview.png" alt="DevLorem Preview">
9+
10+
<p>&nbsp;</p>
11+
12+
13+
## About DevLorem
14+
15+
DevLorem is a small tool that generates Lorem Ipsum paragraphs from movie quotes, based on the different actors.
16+
It can be used as a command line tool, or can be run as a website that offers both a user interface to generate the
17+
paragraphs and an API.
18+
19+
20+
---
21+
22+
23+
## Download DevLorem
24+
25+
The latest version of the tool can be found on the [releases page](https://github.com/Kovah/DevLorem/releases).
26+
Please download the archive file of the latest release suitable for your operating system. Unpack the zip and make the
27+
binary executable.
28+
Alternatively, you can use the Docker image. Details about the usage can be found further down.
29+
30+
31+
## The command line tool
32+
33+
The command line tool can be used to quickly generate paragraphs within your terminal or in scripts. It is available
34+
as the `generate` command and has some optional parameters.
35+
36+
```
37+
devlorem generate
38+
```
39+
40+
Usage:
41+
devlorem generate [flags]
42+
43+
Flags:
44+
-f, --format string Format of the returned paragraphs, either json or text (default json)
45+
-h, --help help for generate
46+
-n, --number int Number of paragraphs returned (default 5)
47+
-p, --paragraphs Show paragraph tags (<p> and </p>) in the generated paragraphs
48+
49+
50+
#### Examples
51+
52+
* `devlorem generate` would get you 5 quotes in JSON without `<p>` tags
53+
* `devlorem generate -n 15 -p` would get you 15 quotes in JSON including the `<p>` tags
54+
* `devlorem generate -n 30 -p -f text` would get you 30 quotes as plain text including the `<p>` tags
55+
* `devlorem generate -n 60 -f text` would get you 60 quotes as plain text without `<p>` tags
56+
57+
58+
---
59+
60+
61+
## The website (user interface + API)
62+
63+
The DevLorem executable ships with a built-in web server including all static assets. You can start the web server by
64+
using the `serve` command. By default, the started web server listens to port 80 on your host.
65+
66+
```
67+
$ devlorem serve
68+
Starting HTTP server for DevLorem...
69+
```
70+
71+
You can now open DevLorem in your browser under `http://localhost`.
72+
73+
If you want to use another port, you can use the optional bind flag. To change the port, specify the port including
74+
preceding colon. In the following example we tell DevLorem to use the port 8090:
75+
76+
```
77+
devlorem serve -b :8090
78+
```
79+
80+
81+
### Usage of the website API
82+
83+
Once the web server is started, the DevLorem API is available too. In the following examples I assume that you have set
84+
up DevLorem behind a proxy with the domain `your-domain.com` and HTTPS configured.
985

1086
Required URL structure:
11-
`your-domain.com/api/[int][/p][/json]`
87+
`https://your-domain.com/api/[int]`
88+
89+
* The results will be returns as Json by default.
90+
* The maximum allowed amount of quotes is `99`.
91+
* Append `paragraphs=true` as a query parameter to show paragraph tags in the output.
92+
* Append `format=text` as a query parameter to get plain text output.
1293

13-
* [int] = optional, number of paragraphs you want
14-
* [/p] = optional, select if the `<p>` tags should be included
15-
* [/json] = optional, output the data in JSON format
1694

1795
#### Examples
1896

19-
* `your-domain.com/api/15/p/json` would get you 15 paragraphs in JSON including the `<p>` tags
20-
* `your-domain.com/api/5/json` would get you 5 paragraphs in JSON without `<p>` tags
21-
* `your-domain.com/api/100/p` would get you 100 paragraphs as plain text including the `<p>` tags
22-
* `your-domain.com/api/100` would get you 100 paragraphs as plain text without `<p>` tags
97+
* `https://your-domain.com/api/5` would get you 5 quotes in JSON without `<p>` tags
98+
* `https://your-domain.com/api/15?paragraphs=true` would get you 15 quotes in JSON including the `<p>` tags
99+
* `https://your-domain.com/api/30?paragraphs=true&format=text` would get you 30 quotes as plain text including the `<p>` tags
100+
* `https://your-domain.com/api/60?format=text` would get you 60 quotes as plain text without `<p>` tags
101+
102+
103+
---
104+
105+
106+
## The DevLorem Docker image
107+
108+
DevLorem is also available as a [Docker image](https://hub.docker.com/r/kovah/devlorem). It is built using Alpine
109+
Linux and is less than 10 MB large.
110+
111+
To use the command line tool, run the Docker image with the `generate` command. More details about the tool can be
112+
found in the command line documentation above.
113+
114+
```
115+
docker run --rm kovah/devlorem generate
116+
```
117+
118+
To use the website, you have to additionally forward a port. Please notice that DevLorem does not support HTTPS
119+
connections, so you probably need a proxy in front of it.
120+
You can start the web server by using the `serve` command. More details about the command can be found in the website
121+
documentation above.
122+
123+
```
124+
docker run --rm -p 80:80 kovah/devlorem serve
125+
```
126+
23127

24128
---
25129

26-
### Contribution
130+
131+
## Contribution
27132

28133
Want to contribute more source texts? Please create a pull request for the new file that should follow the exact same
29134
styling like the ones that are already available:
30135

31-
* Name the file by the person or thing you want to reference.
32-
* The text file should not contain special characters but can contain spaces.
33-
* Place all paragraphs into `<p></p>` tags.
136+
* Filename must contain the name (lowercase, spaces replaced with dashes).
137+
* The JSON strcuture must match the existing files.
138+
* Do not use any <p> tags in the quotes.
139+
34140

35141
---
36142

143+
144+
## Development and Compilation
145+
146+
### Development
147+
148+
You need the following packages on your machine to be able to work on DevLorem and compile the binary:
149+
150+
* github.com/spf13/cobra
151+
* github.com/gorilla/mux
152+
* github.com/GeertJohan/go.rice
153+
* github.com/GeertJohan/go.rice/rice
154+
155+
This can be done by running `go mod download` in the current project directory.
156+
157+
To test the package, compile it and then run the resulting executable. I recommend using [Goland]()
158+
for local development.
159+
160+
161+
### Compilation
162+
163+
To compile the binary and run it locally in the same folder, run the following command:
164+
165+
```
166+
go build
167+
```
168+
169+
To generate a single binary without any dependencies, you have to generate the needed content file for that:
170+
```
171+
rice embed-go
172+
# then run the build command
173+
go build
174+
```
175+
176+
177+
---
178+
179+
37180
DevLorem is a project by [Kovah](https://kovah.de) | [Contributors](https://github.com/Kovah/DevLorem/graphs/contributors)

api.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

assets/dist/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
styles.css

0 commit comments

Comments
 (0)