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
7de56999
Commit
7de56999
authored
Aug 06, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add websocket handler
parent
96e3edd8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
+69
-2
go.mod
go.mod
+2
-0
go.sum
go.sum
+2
-0
proxy.go
proxy.go
+65
-2
No files found.
go.mod
View file @
7de56999
module github.com/sktt1ryze/ygopro-proxy
go 1.17
require github.com/gorilla/websocket v1.5.0 // indirect
go.sum
0 → 100644
View file @
7de56999
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
proxy.go
View file @
7de56999
...
...
@@ -2,8 +2,71 @@ package main
import
(
"fmt"
"log"
"net/http"
"github.com/gorilla/websocket"
)
const
TARGET_PORT
=
":8000"
const
PROXY_PORT
=
":3344"
var
upgrader
=
websocket
.
Upgrader
{
ReadBufferSize
:
0x1000
,
WriteBufferSize
:
0x1000
,
}
func
homePage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Fprintf
(
w
,
"Home Page"
)
}
func
ygoEndpoint
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
upgrader
.
CheckOrigin
=
wsChecker
ws
,
err
:=
upgrader
.
Upgrade
(
w
,
r
,
nil
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
ws
.
Close
()
log
.
Println
(
"Websocket connected"
)
proxyHandler
(
ws
)
}
func
proxyHandler
(
ws
*
websocket
.
Conn
)
{
// todo: spawn channel
for
{
messageType
,
buf
,
err
:=
ws
.
ReadMessage
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
return
}
if
messageType
==
websocket
.
CloseMessage
{
log
.
Println
(
"Websocket closed"
)
return
}
fmt
.
Println
(
string
(
buf
))
if
err
:=
ws
.
WriteMessage
(
messageType
,
buf
);
err
!=
nil
{
log
.
Fatal
(
err
)
return
}
}
}
func
wsChecker
(
r
*
http
.
Request
)
bool
{
return
true
}
func
setupRoutes
()
{
http
.
HandleFunc
(
"/"
,
homePage
)
http
.
HandleFunc
(
"/ygo"
,
ygoEndpoint
)
}
func
main
()
{
fmt
.
Println
(
"hello, ygopro-proxy"
)
setupRoutes
()
log
.
Fatal
(
http
.
ListenAndServe
(
TARGET_PORT
,
nil
))
}
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