Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed Aug 26, 2021
1 parent 7ba980a commit 1d8de11
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 31 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: build

on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
-
name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Tests
run: |
go mod tidy
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins
judas

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
/.idea/
/dist/
46 changes: 46 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
# https://goreleaser.com/customization/build/
project_name: proxycheck
gomod:
proxy: true
builds:
- env: [CGO_ENABLED=0]
binary: proxycheck
main: ./main.go
ldflags:
- -s -w -X main.Version={{.Version}} -X main.Commit={{.ShortCommit}} -X main.Date={{.Date}} -X main.Branch={{.Branch}}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- 386
- arm64
ignore:
- goos: darwin
goarch: 386
archives:
-
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
nfpms:
- maintainer: becivells
description: judas
homepage: https://github.com/Becivells/wsproxycheck
license: MIT
formats:
- deb
- rpm
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.DEFAULT_GOAL:=help

COLOR_ENABLE=$(shell tput colors > /dev/null; echo $$?)
ifeq "$(COLOR_ENABLE)" "0"
CRED:=$(shell tput setaf 1 2>/dev/null)
CGREEN:=$(shell tput setaf 2 2>/dev/null)
CYELLOW:=$(shell tput setaf 3 2>/dev/null)
CBLUE:=$(shell tput setaf 4 2>/dev/null)
CMAGENTA:=$(shell tput setaf 5 2>/dev/null)
CCYAN:=$(shell tput setaf 6 2>/dev/null)
CWHITE:=$(shell tput setaf 7 2>/dev/null)
CEND:=$(shell tput sgr0 2>/dev/null)
endif
.PHONY: build
build: ## build snapshot
@echo "$(CGREEN)build snapshot no publish ...$(CEND)"
@goreleaser build --snapshot --rm-dist

.PHONY: snapshot
snapshot: ## pre snapshot
@echo "$(CGREEN)release snapshot no publish ...$(CEND)"
@goreleaser release --skip-publish --snapshot --rm-dist
.PHONY: release
release: ## release no publish
@echo "$(CGREEN)release no publish ...$(CEND)"
@goreleaser release --skip-publish --rm-dist

.PHONY: clean
clean: ## clean up
@echo "$(CGREEN)clean up dist ...$(CEND)"
@rm -rf ./dist
.PHONY: help
help: ## Show this help.
@echo "$(CGREEN)project$(CEND)"
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make $(CYELLOW)<target>$(CEND) (default: help)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " $(CCYAN)%-12s$(CEND) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
42 changes: 16 additions & 26 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

<!doctype html>
<html>
<head>
<title>Proxy Detect</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Proxy Detect</title>
<style>
body {
font-family: monospace;
Expand All @@ -15,49 +17,37 @@ <h2>Proxy Detect (TCP Win)</h2>
status: <span id="textProxy">...</span>
</div>
<script>
var buf = new Uint8Array(1024 * 150)
var buf = new Uint8Array(1024)
host = window.location.host;
var ws = new WebSocket("ws://" + host + "/echo")

console.log('connecting...')
var lastBufLen = -1

function update() {
var bufLen = ws.bufferedAmount
if (bufLen !== lastBufLen) {
lastBufLen = bufLen
console.log('bufferedAmount:', bufLen, performance.now())
}
}

var tid
//打开 websocket
ws.onopen = function () {
ws.onopen = function() {
console.log('onopen')
}
// 发送消息
ws.onmessage = function (e) {
ws.onmessage = function(e) {
console.log('onmessage. recv: %d bytes', e.data.length)
send()
send()
console.log(ws.bufferedAmount)
console.log('start write:', performance.now())
// tid = setInterval(update, 1)
// console.log('start write:', performance.now())
// tid = setInterval(trace, 1)

setTimeout(function () {
console.log(ws.bufferedAmount)
// 全部发出去则为代理
for (let i = 0; i < 1024; i++) {
send()
}
setTimeout(function() {
textProxy.textContent = !ws.bufferedAmount
}, 1000)
}
ws.onclose = function () {
ws.onclose = function() {
console.log('onclose')
// update()
// trace()
clearInterval(tid)
}
ws.onerror = function () {
ws.onerror = function() {
console.log('onerror')
}

function send() {
ws.send(buf)
}
Expand Down
31 changes: 26 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ package main
import (
_ "embed"
"flag"
"fmt"
"github.com/gorilla/websocket"
"log"
"net/http"

"github.com/gorilla/websocket"
"os"
)

var (
Version = "unknown"
Commit = "unknown"
Date = "unknown"
Branch = "unknown"
)
var addr = flag.String("addr", "0.0.0.0:8083", "http service address")
var sv = flag.Bool("v", false, "show version")

var upgrader = websocket.Upgrader{
ReadBufferSize: 1,
Expand All @@ -19,10 +27,19 @@ var upgrader = websocket.Upgrader{
},
} // use default options

func showVersion() {
fmt.Printf("Current Version: %s\n", Version)
fmt.Printf("Current branch: %s\n", Branch)
fmt.Printf("Current commit: %s\n", Commit)
fmt.Printf("Current date: %s\n", Date)
os.Exit(0)
}

//go:embed index.html
var indexPage []byte

func index(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache")
w.Write(indexPage)
}

Expand All @@ -35,22 +52,23 @@ func echo(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session")
// 允许浏览器(客户端)可以解析的头部 (重要)
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers")
//设置缓存时间
w.Header().Set("Access-Control-Max-Age", "172800")
//允许客户端传递校验信息比如 cookie (重要)
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Cache-Control", "no-cache")
c, err := upgrader.Upgrade(w, r, nil)

if err != nil {
log.Print("upgrade:", err)
return
}
defer c.Close()
c.WriteMessage(1, []byte("aaa"))
c.WriteMessage(1, []byte(""))
c.SetReadLimit(1)

for {

_, message, err := c.ReadMessage()
//time.Sleep(time.Duration(1)*time.Second)
if err != nil {
log.Println("read:", err)
break
Expand All @@ -61,6 +79,9 @@ func echo(w http.ResponseWriter, r *http.Request) {

func main() {
flag.Parse()
if *sv {
showVersion()
}
log.SetFlags(0)
http.HandleFunc("/", index)
http.HandleFunc("/echo", echo)
Expand Down

0 comments on commit 1d8de11

Please sign in to comment.