-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
36 lines (30 loc) · 826 Bytes
/
structs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"log"
"net"
)
type App struct {
Name string `json:"Name"`
Ports []int `json:"Ports"`
Targets []string `json:"Targets"`
}
type Config struct {
Apps []App `json:"Apps"`
}
type Server struct {
Port int `json:"Ports"`
Targets []string `json:"Targets"`
}
func (s Server) Listen(channel chan net.Conn) {
listenAddr := fmt.Sprintf("localhost:%d", s.Port)
listener, err := net.Listen("tcp", listenAddr)
handleErrors(fmt.Sprintf("Error occured while listening on address %s", listenAddr), err)
defer listener.Close()
for {
conn, err := listener.Accept()
log.Println("Recieved a connection on ", conn.LocalAddr().String())
handleErrors(fmt.Sprintf("Error occured while accepting connections on address %s", listenAddr), err)
go func() { channel <- conn }()
}
}