docker + go
This commit is contained in:
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["python", "app.py"]
|
||||||
7
ScannerGO/go.mod
Normal file
7
ScannerGO/go.mod
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module ScannerGO
|
||||||
|
|
||||||
|
go 1.25.7
|
||||||
|
|
||||||
|
require github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||||
|
|
||||||
|
require golang.org/x/sys v0.41.0 // indirect
|
||||||
4
ScannerGO/go.sum
Normal file
4
ScannerGO/go.sum
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||||
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||||
|
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||||
|
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
72
ScannerGO/main.go
Normal file
72
ScannerGO/main.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/tarm/serial"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
portName := flag.String("port", "/dev/ttyACM0", "Serial port name")
|
||||||
|
endpoint := flag.String("url", "https://scanner.sekidesu.xyz/scan", "Target URL endpoint")
|
||||||
|
baudRate := flag.Int("baud", 115200, "Baud rate")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
config := &serial.Config{
|
||||||
|
Name: *portName,
|
||||||
|
Baud: *baudRate,
|
||||||
|
ReadTimeout: time.Second * 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
port, err := serial.OpenPort(config)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error opening port %s: %v\n", *portName, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer port.Close()
|
||||||
|
|
||||||
|
fmt.Printf("Listening on %s (Baud: %d)...\n", *portName, *baudRate)
|
||||||
|
fmt.Printf("Sending data to: %s\n", *endpoint)
|
||||||
|
|
||||||
|
buf := make([]byte, 128)
|
||||||
|
for {
|
||||||
|
n, err := port.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
fmt.Printf("Read error: %v\n", err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if n > 0 {
|
||||||
|
content := strings.TrimSpace(string(buf[:n]))
|
||||||
|
if content != "" {
|
||||||
|
sendToEndpoint(*endpoint, content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendToEndpoint(baseURL, content string) {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
fullURL := fmt.Sprintf("%s?content=%s", baseURL, url.QueryEscape(content))
|
||||||
|
|
||||||
|
resp, err := client.Get(fullURL)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Network Error: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
fmt.Printf("Data: [%s] | Status: %s\n", content, resp.Status)
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
Flask==3.1.3
|
Flask==3.1.3
|
||||||
Flask-Login==0.6.3
|
Flask-Login==0.6.3
|
||||||
Flask-SocketIO==5.6.1
|
Flask-SocketIO==5.6.1
|
||||||
pyserial==3.5
|
|
||||||
requests==2.32.5
|
requests==2.32.5
|
||||||
eventlet==0.36.1
|
eventlet==0.36.1
|
||||||
Reference in New Issue
Block a user