Skip to content

Commit

Permalink
edited api service to accept tls as well if given nil it will run as …
Browse files Browse the repository at this point in the history
…usual
  • Loading branch information
parsa committed Sep 2, 2023
1 parent 6a5ec9d commit 2d8af77
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions foreignusage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,41 @@ package foreignusage
import (
"errors"
"fmt"
"log"
"os"

"github.com/Kawaii-Konnections-KK-Limited/Hayasashiken/foreignusage/api"
)

func InitService() {
func InitService(certFile, keyFile *string) {

port := os.Getenv("PORT")
addr := os.Getenv("ADDRESS")

if port == "" {
fmt.Println(errors.New("please set PORT environment variable"))
port = "8080"
fmt.Println("Defaulting to port ", port)

}
if addr == "" {
fmt.Println(errors.New("please set ADDRESS environment variable"))
addr = "0.0.0.0"
fmt.Println("Defaulting to addr ", addr)
}
if addr != "" && certFile != nil && keyFile != nil {
log.Println("running with tls")
api.InitRouter().RunTLS(fmt.Sprintf("%s:%s", addr, port), *certFile, *keyFile)
} else {
log.Println("running without tls")

err := api.InitRouter().Run(":" + port)

if err != nil {
return
api.InitRouter().Run(fmt.Sprintf("%s:%s", addr, port))
}

// err := api.InitRouter().Run(":" + port)

// if err != nil {
// return
// }

}

0 comments on commit 2d8af77

Please sign in to comment.