feat: Update go-grip to use golangci-lint and improve build process
This commit updates the go-grip project to use golangci-lint for code quality checks, improves the build process by adding a check for formatting errors, and enhances the release workflow by using the new golangci-lint action. The changes address issues with code quality and maintainability, ensuring that the project adheres to best practices. The improved build process reduces the risk of formatting errors, while the updated release workflow ensures that the project is properly formatted before being released.
This commit is contained in:
BIN
.github/docs/examples.png
vendored
Normal file
BIN
.github/docs/examples.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 KiB |
BIN
.github/docs/logo-1.png
vendored
Normal file
BIN
.github/docs/logo-1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
BIN
.github/logo-1.png
vendored
BIN
.github/logo-1.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 41 KiB |
36
.github/workflows/build.yml
vendored
Normal file
36
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.22
|
||||
|
||||
- name: Build
|
||||
run: make build
|
||||
|
||||
- name: Run tests
|
||||
run: make test
|
||||
|
||||
- name: Format
|
||||
run: |
|
||||
DIFF="$(gofmt -d .)"
|
||||
if [[ -n $DIFF ]]; then
|
||||
echo "$DIFF"
|
||||
echo "please run gofmt"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: v1.60
|
||||
35
.github/workflows/release.yml
vendored
Normal file
35
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
releases-matrix:
|
||||
name: Release Go Binary
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
# build and publish in parallel:
|
||||
# linux/386, linux/amd64, linux/arm64
|
||||
# windows/386, windows/amd64, windows/arm64
|
||||
# darwin/amd64, darwin/arm64
|
||||
goos: [linux, windows, darwin]
|
||||
goarch: ["386", amd64, arm64]
|
||||
exclude:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
goversion: 1.22
|
||||
binary_name: "go-grip"
|
||||
extra_files: LICENSE README.md
|
||||
55
README.md
55
README.md
@@ -1,16 +1,59 @@
|
||||
<!-- PROJECT LOGO -->
|
||||
<br />
|
||||
<div align="center">
|
||||
<a href="#">
|
||||
<img src=".github/logo-1.png" alt="Logo" height="80">
|
||||
<img src=".github/docs/logo-1.png" alt="Logo" height="120">
|
||||
</a>
|
||||
|
||||
<h3 align="center">go-grip</h3>
|
||||
|
||||
<p align="center">
|
||||
Render your markdown files local<br>- with the look of GitHub
|
||||
</p>
|
||||
</div>
|
||||
|
||||
# go-grip
|
||||
## Getting started
|
||||
|
||||
## Getting started on macOS
|
||||
|
||||
To get started on a bare `macOS` installation, first install Nix:
|
||||
To install go-grip, simply:
|
||||
|
||||
```bash
|
||||
go install github.com/chrishrb/go-grip@latest
|
||||
```
|
||||
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
|
||||
|
||||
## Usage
|
||||
|
||||
To render a markdown file simply execute:
|
||||
|
||||
```bash
|
||||
go-grip README.md
|
||||
```
|
||||
|
||||
The browser will automatically be opened on http://localhost:6419. You can disable this behaviour with the `-b=false` option.
|
||||
|
||||
You can also specify a port:
|
||||
|
||||
```bash
|
||||
go-grip -p 80 README.md
|
||||
```
|
||||
|
||||
or just open a file-tree with all available files in the current directory:
|
||||
|
||||
```bash
|
||||
go-grip
|
||||
```
|
||||
|
||||
It's also possible to activate the darkmode:
|
||||
|
||||
```bash
|
||||
go-grip -d .
|
||||
```
|
||||
|
||||
To terminate the current server simply press `CTRL-C`.
|
||||
|
||||
## Examples
|
||||
|
||||
<img src="./.github/docs/examples.png" alt="examples" width="1000"/>
|
||||
|
||||
## Similar tools
|
||||
|
||||
This tool is, like the name already says, a reimplementation of [grip](https://github.com/joeyespo/grip) in go and without using the web API of GitHub.
|
||||
|
||||
10
cmd/root.go
10
cmd/root.go
@@ -10,7 +10,7 @@ import (
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "go-grip [file]",
|
||||
Short: "Render markdown document as html",
|
||||
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
|
||||
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dark, _ := cmd.Flags().GetBool("dark")
|
||||
browser, _ := cmd.Flags().GetBool("browser")
|
||||
@@ -18,7 +18,11 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
client := pkg.Client{Dark: dark, OpenBrowser: browser, Port: port}
|
||||
|
||||
err := client.Serve(args[0])
|
||||
var file string
|
||||
if len(args) == 1 {
|
||||
file = args[0]
|
||||
}
|
||||
err := client.Serve(file)
|
||||
cobra.CheckErr(err)
|
||||
},
|
||||
}
|
||||
@@ -31,7 +35,7 @@ func Execute() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().BoolP("dark", "d", false, "Darkmode")
|
||||
rootCmd.Flags().BoolP("dark", "d", false, "Activate darkmode")
|
||||
rootCmd.Flags().BoolP("browser", "b", true, "Open new browser tab")
|
||||
rootCmd.Flags().IntP("port", "p", 6419, "Port to use")
|
||||
}
|
||||
|
||||
6
go.mod
6
go.mod
@@ -3,10 +3,16 @@ module github.com/chrishrb/go-grip
|
||||
go 1.22.7
|
||||
|
||||
require (
|
||||
github.com/aarol/reload v1.1.3 // indirect
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
|
||||
github.com/bep/debounce v1.2.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8 // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/spf13/cobra v1.8.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
)
|
||||
|
||||
12
go.sum
12
go.sum
@@ -1,10 +1,18 @@
|
||||
github.com/aarol/reload v1.1.3 h1:cL/LnKVJq1nb9DkOte9kRbPk2qmShFAAItyhvZRlxoA=
|
||||
github.com/aarol/reload v1.1.3/go.mod h1:TmwcyY3/j9gx1Tn3pGjanIQwd/weeFEJFNRTsn7wFDI=
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
|
||||
github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I=
|
||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8 h1:4txT5G2kqVAKMjzidIabL/8KqjIK71yj30YOeuxLn10=
|
||||
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
@@ -12,5 +20,9 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -3,12 +3,15 @@ package pkg
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"text/template"
|
||||
|
||||
"github.com/aarol/reload"
|
||||
)
|
||||
|
||||
type htmlStruct struct {
|
||||
@@ -17,6 +20,9 @@ type htmlStruct struct {
|
||||
}
|
||||
|
||||
func (client *Client) Serve(file string) error {
|
||||
reload := reload.New("./")
|
||||
reload.Log = log.New(io.Discard, "", 0)
|
||||
|
||||
dir := http.Dir("./")
|
||||
chttp := http.NewServeMux()
|
||||
chttp.Handle("/", http.FileServer(dir))
|
||||
@@ -41,12 +47,11 @@ func (client *Client) Serve(file string) error {
|
||||
}
|
||||
})
|
||||
|
||||
addr := fmt.Sprintf("http://localhost:%d/", client.Port)
|
||||
fmt.Printf("Starting server: %s\n", addr)
|
||||
|
||||
addr := fmt.Sprintf("http://localhost:%d", client.Port)
|
||||
if file != "" {
|
||||
addr = path.Join(addr, file)
|
||||
}
|
||||
fmt.Printf("Starting server: %s\n", addr)
|
||||
|
||||
if client.OpenBrowser {
|
||||
err := Open(addr)
|
||||
@@ -55,7 +60,8 @@ func (client *Client) Serve(file string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%d", client.Port), nil)
|
||||
handler := reload.Handle(http.DefaultServeMux)
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%d", client.Port), handler)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
BIN
static/images/favicon.ico
Normal file
BIN
static/images/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -2,7 +2,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Markdown Preview</title>
|
||||
<title>go-grip - markdown preview</title>
|
||||
<link rel="icon" type="image/x-icon" href="/static/images/favicon.ico">
|
||||
{{if .Darkmode }}
|
||||
<link rel="stylesheet" href="/static/css/github-markdown-dark.css">
|
||||
{{else}}
|
||||
|
||||
Reference in New Issue
Block a user