Compare commits
No commits in common. "7f27875bdb3975182be930cf07e24a9144dfdd82" and "06375de8bd37bdb7a52686d77dddada255bde6a3" have entirely different histories.
7f27875bdb
...
06375de8bd
|
@ -1,42 +0,0 @@
|
||||||
name: Lint and test yml
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint_and_test:
|
|
||||||
# if: ${{ !github.event.act }} # Skip during local actions testing
|
|
||||||
if: github.repository == 'garrancode/gocustomurls'
|
|
||||||
# runs-on: [ubuntu-latest, self-hosted]
|
|
||||||
runs-on: [ubuntu-latest]
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
# Uses some of the solutions found here (https://github.com/actions/setup-go/issues/450)
|
|
||||||
go-version: ['', 'oldstable', 'stable']
|
|
||||||
|
|
||||||
steps:
|
|
||||||
# git show-ref v4.2.2
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # git show-ref v4.2.2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup Go version ${{ matrix.go-version }}
|
|
||||||
# git show-ref v5.4.0
|
|
||||||
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # git show-ref v5.4.0
|
|
||||||
with:
|
|
||||||
# Uses the condition found in here (https://github.com/actions/setup-go?tab=readme-ov-file#getting-go-version-from-the-gomod-file)
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- name: Lint with ${{ matrix.go-version }}
|
|
||||||
# git show-ref v6.5.2
|
|
||||||
uses: golangci/golangci-lint-action@8564da7cb3c6866ed1da648ca8f00a258ef0c802 # git show-ref v6.5.2
|
|
||||||
with:
|
|
||||||
args: --timeout=3m --verbose
|
|
||||||
|
|
||||||
- name: Test with ${{ matrix.go-version }}
|
|
||||||
run: |
|
|
||||||
make coverage-full
|
|
|
@ -1,43 +0,0 @@
|
||||||
name: Local workflow for act
|
|
||||||
|
|
||||||
on: [workflow_dispatch]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
local:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
# image to run with act
|
|
||||||
container:
|
|
||||||
# image url (https://github.com/catthehacker/docker_images/pkgs/container/ubuntu/405021598?tag=act-latest)
|
|
||||||
image: ghcr.io/catthehacker/ubuntu:act-latest-20250429@sha256:ed7b477aa8ba68efd4ebdd6c2cc00728cfecf9780babb04383f481201641e793
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
# Uses some of the solutions found here (https://github.com/actions/setup-go/issues/450)
|
|
||||||
go-version: ['', 'oldstable', 'stable']
|
|
||||||
|
|
||||||
steps:
|
|
||||||
# git show-ref v4.2.2
|
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # git show-ref v4.2.2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup Go version ${{ matrix.go-version }}
|
|
||||||
# git show-ref v5.4.0
|
|
||||||
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # git show-ref v5.4.0
|
|
||||||
with:
|
|
||||||
# Uses the condition found in here (https://github.com/actions/setup-go?tab=readme-ov-file#getting-go-version-from-the-gomod-file)
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- name: Lint with ${{ matrix.go-version }}
|
|
||||||
# git show-ref v6.5.2
|
|
||||||
uses: golangci/golangci-lint-action@8564da7cb3c6866ed1da648ca8f00a258ef0c802 # git show-ref v6.5.2
|
|
||||||
with:
|
|
||||||
args: --timeout=3m --verbose
|
|
||||||
|
|
||||||
- name: Test with ${{ matrix.go-version }}
|
|
||||||
run: |
|
|
||||||
make coverage-full
|
|
30
handlers.go
30
handlers.go
|
@ -9,10 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func healthcheck(w http.ResponseWriter, r *http.Request) {
|
func healthcheck(w http.ResponseWriter, r *http.Request) {
|
||||||
_, err := w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error writing ok: %+v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadRules(c *Config) http.HandlerFunc {
|
func reloadRules(c *Config) http.HandlerFunc {
|
||||||
|
@ -23,12 +20,7 @@ func reloadRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, e.Error(), http.StatusInternalServerError)
|
http.Error(w, e.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
if err != nil {
|
|
||||||
e := fmt.Errorf("cannot reload rules: %+v", err)
|
|
||||||
http.Error(w, e.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +39,7 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = w.Write(data)
|
w.Write(data)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +71,7 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = w.Write(data)
|
w.Write(data)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,10 +94,6 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", "public, max-age=500")
|
w.Header().Set("Cache-Control", "public, max-age=500")
|
||||||
_, err = w.Write(buf.Bytes())
|
w.Write(buf.Bytes())
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -52,12 +52,7 @@ func main() {
|
||||||
|
|
||||||
confFlag := flags.String("conf", "", "Required. Contains all the configurations options")
|
confFlag := flags.String("conf", "", "Required. Contains all the configurations options")
|
||||||
|
|
||||||
err := flags.Parse(os.Args[1:])
|
flags.Parse(os.Args[1:])
|
||||||
if err != nil {
|
|
||||||
errorLog.Println("Error: cannot parse command-line arguments")
|
|
||||||
flags.Usage()
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(flags.Args()) > 1 {
|
if len(flags.Args()) > 1 {
|
||||||
errorLog.Println("Error: too many command-line arguments")
|
errorLog.Println("Error: too many command-line arguments")
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,10 +9,7 @@ import (
|
||||||
func serveLogger(l *LogFile) func(http.HandlerFunc) http.HandlerFunc {
|
func serveLogger(l *LogFile) func(http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
err := l.WriteLog(r)
|
l.WriteLog(r)
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error writing log : %+v", err)
|
|
||||||
}
|
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,12 @@ func walkMatch(t *testing.T, root, pattern string) []string {
|
||||||
// return !errors.Is(err, fs.ErrNotExist)
|
// return !errors.Is(err, fs.ErrNotExist)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func removeFileForTest(t *testing.T, name string) {
|
func removeFileForTest(t *testing.T, name string) {
|
||||||
// err := os.Remove(name)
|
err := os.Remove(name)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
func writeJsonForTest(t *testing.T, data map[string]any, fp string) {
|
func writeJsonForTest(t *testing.T, data map[string]any, fp string) {
|
||||||
jsonString, _ := json.Marshal(data)
|
jsonString, _ := json.Marshal(data)
|
||||||
|
|
Loading…
Reference in New Issue