changes
This commit is contained in:
parent
9cdec27808
commit
6571dc20c0
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
// "crypto/rand"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
|
@ -27,39 +26,28 @@ func main() {
|
|||
log.Fatalf("server: loadkeys: %s", err)
|
||||
}
|
||||
config := tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
host, err := env.GetHost()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
port, err := env.GetPort()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
srv := http.Server{
|
||||
Addr: fmt.Sprintf("127.0.0.1:%d", env.Port),
|
||||
Addr: fmt.Sprintf("%s:%d", host, port),
|
||||
TLSConfig: &config,
|
||||
ReadTimeout: time.Minute,
|
||||
WriteTimeout: time.Minute,
|
||||
Handler: http.HandlerFunc(handle),
|
||||
}
|
||||
srv.Handler = http.HandlerFunc(handle)
|
||||
log.Printf("Start http server on %s:%d\n", host, port)
|
||||
err = srv.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start server: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer srv.Close()
|
||||
// listener, err := tls.Listen("tcp", url, &config)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// defer listener.Close()
|
||||
|
||||
// fmt.Println("Server is listening on port 8080")
|
||||
//
|
||||
// for {
|
||||
// // Wait for a connection.
|
||||
// conn, err := srv.Accept()
|
||||
// if err != nil {
|
||||
// log.Print(err)
|
||||
// continue
|
||||
// }
|
||||
// // Handle the connection in a new goroutine.
|
||||
// // The loop then returns to accepting, so that
|
||||
// // multiple connections may be served concurrently.
|
||||
// go handleConnection(conn)
|
||||
// }
|
||||
}
|
||||
|
||||
func handleConnection(conn net.Conn) {
|
||||
|
|
24
env/env.go
vendored
24
env/env.go
vendored
|
@ -1,6 +1,30 @@
|
|||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"git.qowevisa.me/Qowevisa/gotell/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
Port = 2993
|
||||
ConnectPort = 443
|
||||
)
|
||||
|
||||
func GetHost() (string, error) {
|
||||
host := os.Getenv("GOTELL_HOST")
|
||||
if host == "" {
|
||||
return host, errors.ENV_EMPTY
|
||||
}
|
||||
return host, nil
|
||||
}
|
||||
|
||||
func GetPort() (int, error) {
|
||||
portStr := os.Getenv("GOTELL_PORT")
|
||||
if portStr == "" {
|
||||
return 0, errors.ENV_EMPTY
|
||||
}
|
||||
port, err := strconv.ParseInt(portStr, 10, 32)
|
||||
return int(port), err
|
||||
}
|
||||
|
|
7
errors/env.go
Normal file
7
errors/env.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package errors
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ENV_EMPTY = errors.New("Environment variable was empty")
|
||||
)
|
Loading…
Reference in New Issue
Block a user