cwtch/server/app/main.go

36 lines
863 B
Go
Raw Normal View History

2018-03-30 21:16:51 +00:00
package main
import (
cwtchserver "git.mascherari.press/cwtch/server"
2018-05-03 22:45:50 +00:00
"github.com/s-rah/go-ricochet/utils"
"io/ioutil"
"log"
"os"
2018-03-30 21:16:51 +00:00
)
2018-05-03 22:45:50 +00:00
const privateKeyFile = "./private_key"
func checkAndGenPrivateKey(privateKeyFile string) {
2018-05-20 19:58:16 +00:00
if _, err := os.Stat(privateKeyFile); os.IsNotExist(err) {
2018-05-03 22:45:50 +00:00
log.Printf("no private key found!")
log.Printf("generating new private key...")
2018-05-03 22:45:50 +00:00
pk, pk_err := utils.GeneratePrivateKey()
2018-05-20 19:58:16 +00:00
if pk_err != nil {
2018-05-03 22:45:50 +00:00
log.Fatalf("error generating new private key: %v\n", err)
}
2018-05-03 22:45:50 +00:00
err := ioutil.WriteFile(privateKeyFile, []byte(utils.PrivateKeyToString(pk)), 0400)
2018-05-03 22:45:50 +00:00
if err != nil {
log.Fatalf("error writing new private key to file %s: %v\n", privateKeyFile, err)
}
}
}
2018-03-30 21:16:51 +00:00
func main() {
2018-05-03 22:45:50 +00:00
checkAndGenPrivateKey(privateKeyFile)
2018-03-30 21:16:51 +00:00
server := new(cwtchserver.Server)
log.Printf("starting cwtch server...")
2018-05-03 22:45:50 +00:00
server.Run(privateKeyFile)
2018-03-30 21:16:51 +00:00
}