-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 99ec0c2
Showing
15 changed files
with
525 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-20.04, windows-2019] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: 'recursive' | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20.10 | ||
- name: Install dependencies | ||
run: go get . | ||
- name: Build | ||
shell: bash | ||
run: | | ||
if [ "${{ matrix.os }}" = "ubuntu-20.04" ]; then | ||
go build -trimpath -ldflags "-s -w" -o httpdump httpdump.go | ||
elif [ "${{ matrix.os }}" = "windows-2019" ]; then | ||
go build -trimpath -ldflags "-s -w" -o httpdump.exe httpdump.go | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Release Setup | ||
|
||
on: | ||
workflow_call | ||
|
||
jobs: | ||
release: | ||
name: "Continuous Release" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Job info | ||
run: | | ||
echo "GitHub Ref: ${{ github.ref }}" | ||
- name: Delete old workflow runs | ||
uses: Mattraks/delete-workflow-runs@main | ||
with: | ||
retain_days: 2 | ||
keep_minimum_runs: 2 | ||
- name: Automatic release | ||
uses: "marvinpinto/action-automatic-releases@latest" | ||
if: startsWith(github.ref, 'refs/heads/') | ||
with: | ||
repo_token: "${{ secrets.GITHUB_TOKEN }}" | ||
automatic_release_tag: "continuous" | ||
prerelease: true | ||
title: "Continuous release" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Release | ||
|
||
on: | ||
workflow_dispatch | ||
|
||
jobs: | ||
setup: | ||
name: Setup | ||
uses: ./.github/workflows/release-setup.yml | ||
build: | ||
name: Build | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
build: [linux, linux-aarch64, linux-armv7, linux-mipsle, windows] | ||
include: | ||
- build: linux | ||
os: ubuntu-20.04 | ||
archive-name: httpdump-linux-amd64.tar.gz | ||
- build: linux-aarch64 | ||
os: ubuntu-20.04 | ||
archive-name: httpdump-linux-aarch64.tar.gz | ||
- build: linux-armv7 | ||
os: ubuntu-20.04 | ||
archive-name: httpdump-linux-armv7.tar.gz | ||
- build: linux-mipsle | ||
os: ubuntu-20.04 | ||
archive-name: httpdump-linux-mipsle.tar.gz | ||
- build: windows | ||
os: windows-2019 | ||
archive-name: httpdump-windows10-amd64.7z | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: 'recursive' | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20.10 | ||
- name: Install dependencies | ||
run: go get . | ||
- name: Build | ||
shell: bash | ||
run: | | ||
if [ "${{ matrix.build }}" = "linux" ]; then | ||
go build -trimpath -ldflags "-s -w" -o httpdump httpdump.go | ||
elif [ "${{ matrix.build }}" = "linux-aarch64" ]; then | ||
GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o httpdump httpdump.go | ||
elif [ "${{ matrix.build }}" = "linux-armv7" ]; then | ||
GOOS=linux GOARM=7 GOARCH=arm go build -trimpath -ldflags "-s -w" -o httpdump httpdump.go | ||
elif [ "${{ matrix.build }}" = "linux-mipsle" ]; then | ||
GOOS=linux GOARCH=mipsle go build -trimpath -ldflags "-s -w" -o httpdump httpdump.go | ||
elif [ "${{ matrix.build }}" = "windows" ]; then | ||
go build -trimpath -ldflags "-s -w" -o httpdump.exe httpdump.go | ||
fi | ||
- name: Build archive | ||
shell: bash | ||
run: | | ||
mkdir archive | ||
cp LICENSE README.md archive/ | ||
# ls -lR | ||
if [ "${{ matrix.build }}" = "windows" ]; then | ||
cp httpdump.exe ./archive/ | ||
cd archive | ||
7z a "${{ matrix.archive-name }}" LICENSE README.md httpdump.exe | ||
else | ||
cp httpdump ./archive/ | ||
cd archive | ||
tar -czf "${{ matrix.archive-name }}" LICENSE README.md httpdump | ||
fi | ||
- name: Continuous release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/heads/') | ||
with: | ||
prerelease: false | ||
files: archive/${{ matrix.archive-name }} | ||
tag_name: continuous | ||
|
||
- if: startsWith(github.ref, 'refs/tags/') | ||
name: Tagged release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: archive/${{ matrix.archive-name }} | ||
name: Release build (${{ github.ref_name }}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.idea/* | ||
!.idea/codeStyles | ||
!.idea/*.iml | ||
!.idea/modules.xml | ||
|
||
test.go | ||
httpdump | ||
httpdump.log |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="go build httpdump" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true"> | ||
<module name="httpdump" /> | ||
<working_directory value="$PROJECT_DIR$" /> | ||
<go_parameters value="-o httpdump" /> | ||
<kind value="FILE" /> | ||
<package value="httpdump" /> | ||
<directory value="$PROJECT_DIR$" /> | ||
<filePath value="$PROJECT_DIR$/httpdump.go" /> | ||
<output_directory value="$PROJECT_DIR$" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 TLSLink | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## httpdump | ||
|
||
``` | ||
Usage: ./httpdump [options] | ||
Options: | ||
-p string | ||
http port (default "8080") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module httpdump | ||
|
||
go 1.21 | ||
|
||
require github.com/gofiber/fiber/v2 v2.50.0 | ||
|
||
require ( | ||
github.com/andybalholm/brotli v1.0.5 // indirect | ||
github.com/google/uuid v1.3.1 // indirect | ||
github.com/klauspost/compress v1.16.7 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasthttp v1.50.0 // indirect | ||
github.com/valyala/tcplisten v1.0.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= | ||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= | ||
github.com/gofiber/fiber/v2 v2.50.0 h1:ia0JaB+uw3GpNSCR5nvC5dsaxXjRU5OEu36aytx+zGw= | ||
github.com/gofiber/fiber/v2 v2.50.0/go.mod h1:21eytvay9Is7S6z+OgPi7c7n4++tnClWmhpimVHMimw= | ||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= | ||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= | ||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= | ||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= | ||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= | ||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= | ||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= | ||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= | ||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= | ||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= | ||
github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= | ||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= | ||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | ||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/gofiber/fiber/v2" | ||
"httpdump/pkg/log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
port := flag.String("p", "8080", "http port") | ||
respType := flag.String("t", "html", "response Content-Type: html, json, txt") | ||
logPath := flag.String("l", "", "log path") | ||
|
||
flag.Usage = func() { | ||
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0]) | ||
fmt.Fprintf(os.Stderr, "Options:\n") | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
|
||
// init logger | ||
log.Init(*logPath, "trace") | ||
|
||
app := fiber.New(fiber.Config{ | ||
DisableStartupMessage: true, | ||
DisableDefaultDate: true, | ||
DisableHeaderNormalizing: true, | ||
DisableDefaultContentType: true, | ||
}) | ||
// Match any request | ||
app.Use(func(c *fiber.Ctx) error { | ||
log.Trace(c.IP(), c.Request().String()) | ||
err := c.Next() | ||
// print response | ||
// log.Debug(c.Response().String()) | ||
return err | ||
}) | ||
app.Get("/", func(c *fiber.Ctx) error { | ||
switch *respType { | ||
case "json": | ||
return c.JSON(fiber.Map{"hello": "world"}) | ||
case "txt": | ||
c.Set("Content-Type", "text/plain; charset=utf-8") | ||
return c.SendString("hello world") | ||
default: | ||
c.Set("Content-Type", "text/html; charset=utf-8") | ||
return c.SendString("hello world") | ||
} | ||
}) | ||
// fmt.Println(*port) | ||
go log.Fatal(app.Listen(fmt.Sprintf(":%s", *port))) | ||
|
||
watchSignal() | ||
} | ||
|
||
func watchSignal() { | ||
log.Info("Server pid:", os.Getpid()) | ||
|
||
sigs := make(chan os.Signal, 1) | ||
// https://pkg.go.dev/os/signal | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) | ||
for { | ||
// 没有信号就阻塞,从而避免主协程退出 | ||
sig := <-sigs | ||
log.Info("Get signal:", sig) | ||
switch sig { | ||
default: | ||
log.Info("Stop") | ||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.