Validate flags for tls mode

This commit is contained in:
Kelvin Clement Mwinuka
2023-06-17 22:20:40 +08:00
parent d787489fb5
commit c843093d18

View File

@@ -1,9 +1,8 @@
package main package main
import ( import (
"errors"
"flag" "flag"
"log" "fmt"
) )
type Server struct { type Server struct {
@@ -12,12 +11,24 @@ type Server struct {
cert *string cert *string
} }
func (server *Server) Start() error { func (server *Server) Start() {
return errors.New("server start to be implemented")
if *server.tls && (len(*server.key) <= 0 || len(*server.cert) <= 0) {
fmt.Println("Must provide key and certificate file paths for TLS mode.")
return
}
if *server.tls {
fmt.Println("TLS mode activated...")
} else {
fmt.Println("Normal TCP mode...")
}
// Listen to connection
} }
func main() { func main() {
tls := flag.Bool("tls", false, "Start the server in TLS mode.") tls := flag.Bool("tls", false, "Start the server in TLS mode. Default is false")
key := flag.String("key", "", "The private key file path.") key := flag.String("key", "", "The private key file path.")
cert := flag.String("cert", "", "The signed certificate file path.") cert := flag.String("cert", "", "The signed certificate file path.")
@@ -29,9 +40,5 @@ func main() {
cert: cert, cert: cert,
} }
err := server.Start() server.Start()
if err != nil {
log.Fatal(err)
}
} }