Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-proxy
Commits
e4d56fc9
Commit
e4d56fc9
authored
Aug 14, 2022
by
Chunchi Che
Committed by
GitHub
Aug 14, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from DarkNeos/dev
Dev
parents
a566f858
d42f4cf6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
proxy.go
proxy.go
+14
-12
No files found.
proxy.go
View file @
e4d56fc9
...
@@ -2,7 +2,7 @@ package main
...
@@ -2,7 +2,7 @@ package main
import
(
import
(
"bufio"
"bufio"
"
fmt
"
"
io
"
"log"
"log"
"net"
"net"
"net/http"
"net/http"
...
@@ -21,10 +21,6 @@ var upgrader = websocket.Upgrader{
...
@@ -21,10 +21,6 @@ var upgrader = websocket.Upgrader{
WriteBufferSize
:
0x1000
,
WriteBufferSize
:
0x1000
,
}
}
func
homePage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Fprintf
(
w
,
"Home Page"
)
}
func
ygoEndpoint
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
ygoEndpoint
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
...
@@ -40,8 +36,11 @@ func ygoEndpoint(w http.ResponseWriter, r *http.Request) {
...
@@ -40,8 +36,11 @@ func ygoEndpoint(w http.ResponseWriter, r *http.Request) {
tcp
,
err
:=
net
.
Dial
(
"tcp"
,
"127.0.0.1"
+
PROXY_PORT
)
tcp
,
err
:=
net
.
Dial
(
"tcp"
,
"127.0.0.1"
+
PROXY_PORT
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
"connect tcp server error: "
,
err
)
}
}
log
.
Println
(
"Tcp connected"
)
defer
tcp
.
Close
()
defer
tcp
.
Close
()
wg
.
Add
(
2
)
wg
.
Add
(
2
)
...
@@ -54,7 +53,7 @@ func wsProxy(ws *websocket.Conn, tcp *net.Conn, wg *sync.WaitGroup) {
...
@@ -54,7 +53,7 @@ func wsProxy(ws *websocket.Conn, tcp *net.Conn, wg *sync.WaitGroup) {
for
{
for
{
messageType
,
buf
,
err
:=
ws
.
ReadMessage
()
messageType
,
buf
,
err
:=
ws
.
ReadMessage
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
"websocket read message error: "
,
err
)
break
break
}
}
...
@@ -70,7 +69,7 @@ func wsProxy(ws *websocket.Conn, tcp *net.Conn, wg *sync.WaitGroup) {
...
@@ -70,7 +69,7 @@ func wsProxy(ws *websocket.Conn, tcp *net.Conn, wg *sync.WaitGroup) {
_
,
err
=
writer
.
Write
(
buffer
)
_
,
err
=
writer
.
Write
(
buffer
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
"websocket send message error: "
,
err
)
break
break
}
}
}
}
...
@@ -85,7 +84,11 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
...
@@ -85,7 +84,11 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
_
,
err
:=
reader
.
Read
(
buffer
)
_
,
err
:=
reader
.
Read
(
buffer
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
if
err
==
io
.
EOF
{
continue
}
log
.
Fatal
(
"tcp read message error: "
,
err
)
break
break
}
}
...
@@ -93,7 +96,7 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
...
@@ -93,7 +96,7 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
err
=
ws
.
WriteMessage
(
websocket
.
TextMessage
,
buffer
)
// temporary TextMessage, should be BinaryMessage in ygopro
err
=
ws
.
WriteMessage
(
websocket
.
TextMessage
,
buffer
)
// temporary TextMessage, should be BinaryMessage in ygopro
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
"tcp send message error: "
,
err
)
break
break
}
}
}
}
...
@@ -104,8 +107,7 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
...
@@ -104,8 +107,7 @@ func tcpProxy(tcp *net.Conn, ws *websocket.Conn, wg *sync.WaitGroup) {
func
wsChecker
(
r
*
http
.
Request
)
bool
{
return
true
}
func
wsChecker
(
r
*
http
.
Request
)
bool
{
return
true
}
func
setupRoutes
()
{
func
setupRoutes
()
{
http
.
HandleFunc
(
"/"
,
homePage
)
http
.
HandleFunc
(
"/"
,
ygoEndpoint
)
http
.
HandleFunc
(
"/ygo"
,
ygoEndpoint
)
}
}
func
main
()
{
func
main
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment