mirror of
https://github.com/jimeh/casecmp.git
synced 2026-02-19 10:26:40 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15768d9a64 | ||
|
d10ef9f603
|
|||
|
2f658ecfcb
|
|||
|
317782e77e
|
|||
|
2dd53f398a
|
|||
|
88733428f5
|
|||
| 50c538e3b7 | |||
| 90728a4807 | |||
|
de40d5459f
|
|||
| 5b77604aad | |||
|
|
ff5cbcb63d
|
||
|
770dad5e32
|
|||
| c39b4321e3 | |||
|
|
71d0525714 | ||
| a02e372f2a | |||
|
5500933689
|
|||
| 61f987a007 | |||
|
1a9e060f1e
|
|||
| 9da6bec077 | |||
|
438a238547
|
|||
|
37bcb99917
|
|||
|
dfe6ce7c24
|
3
.github/.release-please-manifest.json
vendored
Normal file
3
.github/.release-please-manifest.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
".": "2.4.0"
|
||||||
|
}
|
||||||
26
.github/release-please-config.json
vendored
Normal file
26
.github/release-please-config.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"packages": {
|
||||||
|
".": {
|
||||||
|
"release-type": "go",
|
||||||
|
"changelog-path": "CHANGELOG.md",
|
||||||
|
"bump-minor-pre-major": true,
|
||||||
|
"bump-patch-for-minor-pre-major": true,
|
||||||
|
"draft": false,
|
||||||
|
"always-update": true,
|
||||||
|
"prerelease": false,
|
||||||
|
"extra-files": [
|
||||||
|
{
|
||||||
|
"type": "yaml",
|
||||||
|
"path": "chart/Chart.yaml",
|
||||||
|
"jsonpath": "appVersion"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "yaml",
|
||||||
|
"path": "chart/Chart.yaml",
|
||||||
|
"jsonpath": "version"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
||||||
|
}
|
||||||
95
.github/workflows/ci.yml
vendored
95
.github/workflows/ci.yml
vendored
@@ -4,13 +4,12 @@ on: [push]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: build
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version-file: "go.mod"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
@@ -24,10 +23,8 @@ jobs:
|
|||||||
helm-lint:
|
helm-lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: azure/setup-helm@v3
|
- uses: azure/setup-helm@v4
|
||||||
with:
|
|
||||||
token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
- name: Lint chart
|
- name: Lint chart
|
||||||
run: helm lint chart
|
run: helm lint chart
|
||||||
- name: Template chart
|
- name: Template chart
|
||||||
@@ -35,38 +32,76 @@ jobs:
|
|||||||
|
|
||||||
release-please:
|
release-please:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build, helm-lint]
|
if: startsWith(github.ref, 'refs/heads/')
|
||||||
if: github.ref == 'refs/heads/main'
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
outputs:
|
||||||
|
release_created: ${{ steps.release.outputs.release_created }}
|
||||||
|
tag_name: ${{ steps.release.outputs.tag_name }} # e.g. v1.0.0
|
||||||
|
version: ${{ steps.release.outputs.version }} # e.g. 1.0.0
|
||||||
steps:
|
steps:
|
||||||
- uses: google-github-actions/release-please-action@v3
|
- uses: jimeh/release-please-manifest-action@v2
|
||||||
id: release-please
|
id: release
|
||||||
with:
|
with:
|
||||||
command: manifest
|
target-branch-pattern: '^(main|master|release-[0-9]+(\.[0-9]+)?\.x)$'
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
|
||||||
uses: actions/checkout@v3
|
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build, helm-lint, release-please]
|
||||||
|
if: needs.release-please.outputs.release_created
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
- run: git fetch --force --tags
|
||||||
name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
- uses: docker/setup-buildx-action@v2
|
||||||
uses: docker/setup-buildx-action@v2
|
- name: Docker Login
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
|
||||||
name: Docker Login
|
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
- uses: actions/setup-go@v5
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version-file: "go.mod"
|
||||||
- if: ${{ steps.release-please.outputs.release_created }}
|
- name: Run GoReleaser
|
||||||
name: Run GoReleaser
|
uses: goreleaser/goreleaser-action@v6
|
||||||
uses: goreleaser/goreleaser-action@v2
|
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: '~> v2'
|
||||||
args: release --rm-dist
|
args: release --clean
|
||||||
env:
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
release-chart:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [release, release-please]
|
||||||
|
if: needs.release-please.outputs.release_created
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- run: git fetch --force --tags
|
||||||
|
- name: Configure Git
|
||||||
|
run: |
|
||||||
|
git config user.name "${{ github.actor }}"
|
||||||
|
git config user.email "${{ github.actor }}@users.noreply.github.com"
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v4
|
||||||
|
- name: Run chart-releaser
|
||||||
|
uses: helm/chart-releaser-action@v1
|
||||||
|
with:
|
||||||
|
charts_dir: chart
|
||||||
|
config: .cr.yaml
|
||||||
|
env:
|
||||||
|
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
version: 2
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
@@ -27,28 +28,26 @@ universal_binaries:
|
|||||||
- replace: false
|
- replace: false
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- formats: ["tar.gz"]
|
||||||
name_template: |-
|
name_template: |-
|
||||||
{{ .ProjectName }}-{{ .Version }}_{{ .Os }}_{{ if eq .Arch "all" }}universal{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}
|
{{ .ProjectName }}-{{ .Version }}_{{ if eq .Os "darwin" }}macos{{ else }}{{ .Os }}{{ end }}_{{ if eq .Arch "all" }}universal{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}
|
||||||
wrap_in_directory: true
|
wrap_in_directory: true
|
||||||
format_overrides:
|
format_overrides:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
format: zip
|
formats: ["zip"]
|
||||||
replacements:
|
|
||||||
darwin: macos
|
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: "checksums.txt"
|
name_template: "checksums.txt"
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ .Tag }}-next"
|
version_template: "{{ .Tag }}-next"
|
||||||
|
|
||||||
changelog:
|
changelog:
|
||||||
skip: true
|
disable: true
|
||||||
|
|
||||||
dockers:
|
dockers:
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- "ghcr.io/jimeh/casecmp:{{ .Version }}-amd64"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"
|
||||||
- "ghcr.io/jimeh/casecmp:latest-amd64"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-amd64"
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
use: buildx
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
@@ -56,8 +55,8 @@ dockers:
|
|||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--platform=linux/amd64"
|
- "--platform=linux/amd64"
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- "ghcr.io/jimeh/casecmp:{{ .Version }}-386"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-386"
|
||||||
- "ghcr.io/jimeh/casecmp:latest-386"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-386"
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
use: buildx
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
@@ -65,8 +64,8 @@ dockers:
|
|||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--platform=linux/386"
|
- "--platform=linux/386"
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- "ghcr.io/jimeh/casecmp:{{ .Version }}-arm64"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64"
|
||||||
- "ghcr.io/jimeh/casecmp:latest-arm64"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm64"
|
||||||
use: buildx
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
@@ -74,8 +73,8 @@ dockers:
|
|||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--platform=linux/arm64"
|
- "--platform=linux/arm64"
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- "ghcr.io/jimeh/casecmp:{{ .Version }}-armv6"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-armv6"
|
||||||
- "ghcr.io/jimeh/casecmp:latest-armv6"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-armv6"
|
||||||
use: buildx
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: arm
|
goarch: arm
|
||||||
@@ -84,8 +83,8 @@ dockers:
|
|||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--platform=linux/arm/v6"
|
- "--platform=linux/arm/v6"
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- "ghcr.io/jimeh/casecmp:{{ .Version }}-armv7"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-armv7"
|
||||||
- "ghcr.io/jimeh/casecmp:latest-armv7"
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-armv7"
|
||||||
use: buildx
|
use: buildx
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: arm
|
goarch: arm
|
||||||
@@ -95,17 +94,17 @@ dockers:
|
|||||||
- "--platform=linux/arm/v7"
|
- "--platform=linux/arm/v7"
|
||||||
|
|
||||||
docker_manifests:
|
docker_manifests:
|
||||||
- name_template: ghcr.io/jimeh/casecmp:{{ .Version }}
|
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}"
|
||||||
image_templates:
|
image_templates:
|
||||||
- ghcr.io/jimeh/casecmp:{{ .Version }}-amd64
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"
|
||||||
- ghcr.io/jimeh/casecmp:{{ .Version }}-386
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-386"
|
||||||
- ghcr.io/jimeh/casecmp:{{ .Version }}-arm64
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64"
|
||||||
- ghcr.io/jimeh/casecmp:{{ .Version }}-armv6
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-armv6"
|
||||||
- ghcr.io/jimeh/casecmp:{{ .Version }}-armv7
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-armv7"
|
||||||
- name_template: ghcr.io/jimeh/casecmp:latest
|
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest"
|
||||||
image_templates:
|
image_templates:
|
||||||
- ghcr.io/jimeh/casecmp:latest-amd64
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-amd64"
|
||||||
- ghcr.io/jimeh/casecmp:latest-386
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-386"
|
||||||
- ghcr.io/jimeh/casecmp:latest-arm64
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm64"
|
||||||
- ghcr.io/jimeh/casecmp:latest-armv6
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-armv6"
|
||||||
- ghcr.io/jimeh/casecmp:latest-armv7
|
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-armv7"
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
".": "2.2.0"
|
|
||||||
}
|
|
||||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,5 +1,19 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [2.4.0](https://github.com/jimeh/casecmp/compare/v2.3.0...v2.4.0) (2025-03-16)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* use Go 1.24 and a net/http ServeMux for routing ([#19](https://github.com/jimeh/casecmp/issues/19)) ([50c538e](https://github.com/jimeh/casecmp/commit/50c538e3b78d841bf09653a1571a8019a2126be0))
|
||||||
|
|
||||||
|
## [2.3.0](https://github.com/jimeh/casecmp/compare/v2.2.0...v2.3.0) (2023-04-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **version:** add Go version to version output ([5500933](https://github.com/jimeh/casecmp/commit/55009336891b6c281542cf85498abb04816879d3))
|
||||||
|
|
||||||
## [2.2.0](https://github.com/jimeh/casecmp/compare/v2.1.0...v2.2.0) (2023-03-10)
|
## [2.2.0](https://github.com/jimeh/casecmp/compare/v2.1.0...v2.2.0) (2023-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
NAME = casecmp
|
NAME = casecmp
|
||||||
BINARY = bin/${NAME}
|
BINARY = bin/${NAME}
|
||||||
VERSION ?= $(shell cat VERSION)
|
VERSION ?= $(shell git describe --tags)
|
||||||
SOURCES = $(shell find . -name '*.go' -o -name 'Makefile')
|
SOURCES = $(shell find . -name '*.go' -o -name 'Makefile')
|
||||||
|
|
||||||
$(BINARY): $(SOURCES)
|
$(BINARY): $(SOURCES)
|
||||||
|
|||||||
@@ -1,24 +1,6 @@
|
|||||||
apiVersion: v2
|
apiVersion: v2
|
||||||
name: casecmp
|
name: casecmp
|
||||||
description: A Helm chart for Kubernetes
|
description: A Helm chart for casecmp
|
||||||
|
|
||||||
# A chart can be either an 'application' or a 'library' chart.
|
|
||||||
#
|
|
||||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
|
||||||
# to be deployed.
|
|
||||||
#
|
|
||||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
|
||||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
|
||||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
|
||||||
type: application
|
type: application
|
||||||
|
version: 2.4.0
|
||||||
# This is the chart version. This version number should be incremented each time you make changes
|
appVersion: 2.4.0
|
||||||
# to the chart and its templates, including the app version.
|
|
||||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
|
||||||
version: 2.2.0 # x-release-please-version
|
|
||||||
|
|
||||||
# This is the version number of the application being deployed. This version number should be
|
|
||||||
# incremented each time you make changes to the application. Versions are not expected to
|
|
||||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
|
||||||
# It is recommended to use it with quotes.
|
|
||||||
appVersion: 2.2.0 # x-release-please-version
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module github.com/jimeh/casecmp
|
module github.com/jimeh/casecmp
|
||||||
|
|
||||||
go 1.19
|
go 1.24.1
|
||||||
|
|||||||
79
main.go
79
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -55,6 +56,11 @@ curl -X POST -H "Content-Type: application/json" -d '{"a":"Foo Bar","b":"FOO BAR
|
|||||||
`))
|
`))
|
||||||
|
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != "GET" || r.URL.RawQuery != "" {
|
||||||
|
casecmpHandler(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
scheme := "http"
|
scheme := "http"
|
||||||
if r.TLS != nil || *forceHTTPSFlag {
|
if r.TLS != nil || *forceHTTPSFlag {
|
||||||
scheme = "https"
|
scheme = "https"
|
||||||
@@ -88,20 +94,44 @@ type JSONData struct {
|
|||||||
B string `json:"b"`
|
B string `json:"b"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func casecmpHandler(w http.ResponseWriter, r *http.Request) error {
|
func casecmpHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
equal, err := casecmp(r)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
_, _ = fmt.Fprint(w, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := "0"
|
||||||
|
if equal {
|
||||||
|
resp = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
accept := r.Header.Get("Accept")
|
||||||
|
if strings.Contains(accept, "application/json") {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
_, _ = fmt.Fprintf(w, `{"result":%s}`, resp)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprint(w, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func casecmp(r *http.Request) (bool, error) {
|
||||||
var a, b string
|
var a, b string
|
||||||
|
|
||||||
contentType := r.Header.Get("Content-Type")
|
contentType := r.Header.Get("Content-Type")
|
||||||
if strings.Contains(contentType, "application/json") {
|
if strings.Contains(contentType, "application/json") {
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
d := JSONData{}
|
d := JSONData{}
|
||||||
err = json.Unmarshal(body, &d)
|
err = json.Unmarshal(body, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, fmt.Errorf("invalid JSON request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a = d.A
|
a = d.A
|
||||||
@@ -111,39 +141,7 @@ func casecmpHandler(w http.ResponseWriter, r *http.Request) error {
|
|||||||
b = r.FormValue("b")
|
b = r.FormValue("b")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := "0"
|
return strings.EqualFold(string(a), string(b)), nil
|
||||||
if strings.EqualFold(string(a), string(b)) {
|
|
||||||
resp = "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
accept := r.Header.Get("Accept")
|
|
||||||
if strings.Contains(accept, "application/json") {
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
||||||
_, err := fmt.Fprintf(w, `{"result":%s}`, resp)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := fmt.Fprint(w, resp)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.URL.Path {
|
|
||||||
case "/":
|
|
||||||
if r.Method != "GET" || r.URL.RawQuery != "" {
|
|
||||||
err := casecmpHandler(w, r)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
_, _ = fmt.Fprint(w, err.Error())
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
indexHandler(w, r)
|
|
||||||
case "/about":
|
|
||||||
aboutHandler(w, r)
|
|
||||||
default:
|
|
||||||
http.NotFound(w, r)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printVersion() {
|
func printVersion() {
|
||||||
@@ -154,6 +152,8 @@ func printVersion() {
|
|||||||
buffer.WriteString(fmt.Sprintf(" (%s)", commit))
|
buffer.WriteString(fmt.Sprintf(" (%s)", commit))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer.WriteString(fmt.Sprintf(", built with %s", runtime.Version()))
|
||||||
|
|
||||||
fmt.Println(buffer.String())
|
fmt.Println(buffer.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +181,11 @@ func startServer() error {
|
|||||||
*forceHTTPSFlag = true
|
*forceHTTPSFlag = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/{$}", indexHandler)
|
||||||
|
mux.HandleFunc("/about", aboutHandler)
|
||||||
|
mux.HandleFunc("/about/{$}", aboutHandler)
|
||||||
|
|
||||||
address := fmt.Sprintf("%s:%d", *bindFlag, *portFlag)
|
address := fmt.Sprintf("%s:%d", *bindFlag, *portFlag)
|
||||||
fmt.Printf("Listening on %s\n", address)
|
fmt.Printf("Listening on %s\n", address)
|
||||||
|
|
||||||
@@ -188,7 +193,7 @@ func startServer() error {
|
|||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 5 * time.Second,
|
WriteTimeout: 5 * time.Second,
|
||||||
IdleTimeout: 30 * time.Second,
|
IdleTimeout: 30 * time.Second,
|
||||||
Handler: http.HandlerFunc(handler),
|
Handler: mux,
|
||||||
Addr: address,
|
Addr: address,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"release-type": "go",
|
|
||||||
"bump-minor-pre-major": true,
|
|
||||||
"bump-patch-for-minor-pre-major": true,
|
|
||||||
"packages": {
|
|
||||||
".": {
|
|
||||||
"changelog-path": "CHANGELOG.md",
|
|
||||||
"draft": false,
|
|
||||||
"prerelease": false,
|
|
||||||
"extra-files": [
|
|
||||||
"chart/Chart.yaml"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user