start.go 770 Bytes
Newer Older
ElyKar's avatar
ElyKar committed
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
package cmd

import (
	"fmt"
	"os"
	"strconv"

	dapi "dfss/dfssd/api"
	"dfss/dfsst/server"
	"dfss/net"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

// startCmd represents the start command
var startCmd = &cobra.Command{
	Use:   "start",
	Short: "Start the TTP service",
	Long: `Start the TTP of the DFSS project

Fill the DFSS_TTP_PASSWORD environment variable if the private key is enciphered`,
	Run: func(cmd *cobra.Command, args []string) {
		srv := server.GetServer()

		addrPort := viper.GetString("address") + ":" + strconv.Itoa(viper.GetInt("port"))
		fmt.Println("Listening on " + addrPort)
		dapi.DLog("TTP server started on " + addrPort)
		err := net.Listen(addrPort, srv)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
		}

		dapi.DClose()
	},
}