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
import (
"errors"
"flag"
"log"
"fmt"
)
type Server struct {
@@ -12,12 +11,24 @@ type Server struct {
cert *string
}
func (server *Server) Start() error {
return errors.New("server start to be implemented")
func (server *Server) Start() {
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() {
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.")
cert := flag.String("cert", "", "The signed certificate file path.")
@@ -29,9 +40,5 @@ func main() {
cert: cert,
}
err := server.Start()
if err != nil {
log.Fatal(err)
}
server.Start()
}