main.go (2947B)
1 // This file is part of gnunet-gns-registrar, a GNS registrar service. 2 // Copyright (C) 2022 Martin Schanzenbach 3 // 4 // gnunet-gns-registrar is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Affero General Public License as published 6 // by the Free Software Foundation, either version 3 of the License, 7 // or (at your option) any later version. 8 // 9 // gnunet-gns-registrar is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // 17 // SPDX-License-Identifier: AGPL3.0-or-later 18 19 package main 20 21 import ( 22 "flag" 23 "fmt" 24 "log" 25 "net/http" 26 "os" 27 28 "github.com/schanzen/taler-go/pkg/merchant" 29 gnsregistrar "gnunet.org/gnunet-gns-registrar/pkg/rest" 30 "gopkg.in/ini.v1" 31 "rsc.io/getopt" 32 ) 33 34 var ( 35 t gnsregistrar.Registrar 36 version string 37 datahome string 38 verbose bool // FIXME do something with this? 39 ) 40 41 func handleRequests(r *gnsregistrar.Registrar) { 42 log.Fatal(http.ListenAndServe(r.Cfg.Ini.Section("gns-registrar").Key("bind_to").MustString("localhost:11000"), r.Router)) 43 } 44 45 func printHelp() { 46 fmt.Print("gnunet-gns-registrar\n\n") 47 getopt.PrintDefaults() 48 fmt.Print("\nReport bugs to gnunet-developers@gnu.org.\n", 49 "Home page: https://taler.net\n", 50 "General help using GNU software: http://www.gnu.org/gethelp/\n") 51 } 52 53 func main() { 54 var cfgFlag = flag.String("c", "", "Configuration file to use") 55 getopt.Alias("c", "config") 56 // FIXME use flags 57 loglevelStringOpt := flag.String("L", "INFO", "Log level to use. DEBUG, INFO, WARNING or ERROR") 58 getopt.Alias("L", "loglevel") 59 var verboseFlag = flag.Bool("v", false, "Verbose") 60 getopt.Alias("v", "verbose") 61 var helpFlag = flag.Bool("h", false, "Print help") 62 getopt.Alias("h", "help") 63 64 getopt.Parse() 65 cfgfile := "gns-registrar.conf" 66 log.Println(version) 67 if len(*cfgFlag) != 0 { 68 cfgfile = *cfgFlag 69 } 70 if *helpFlag { 71 printHelp() 72 return 73 } 74 verbose = *verboseFlag 75 loglevel := gnsregistrar.LogInfo 76 for loglevelNum, loglevelString := range gnsregistrar.LoglevelStringMap { 77 if loglevelString == *loglevelStringOpt { 78 loglevel = loglevelNum 79 } 80 } 81 cfg, err := ini.LooseLoad(cfgfile) 82 if err != nil { 83 log.Fatalf("Failed to read config: %v", err) 84 os.Exit(1) 85 } 86 merchURL := cfg.Section("gns-registrar").Key("base_url_merchant").MustString("https://backend.demo.taler.net") 87 merchToken := cfg.Section("gns-registrar").Key("merchant_token").MustString("sandbox") 88 t := gnsregistrar.Registrar{} 89 t.Initialize(gnsregistrar.RegistrarConfig{ 90 Ini: cfg, 91 Version: version, 92 Datahome: datahome, 93 Loglevel: loglevel, 94 Merchant: merchant.NewMerchant(merchURL, merchToken), 95 }) 96 handleRequests(&t) 97 }