cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

main.go (2370B)


      1 // This file is part of taler-cashless2ecash.
      2 // Copyright (C) 2024 Joel Häberli
      3 //
      4 // taler-cashless2ecash 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 // taler-cashless2ecash 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 	"c2ec/internal"
     23 	utils "c2ec/internal/utils"
     24 	"c2ec/pkg/config"
     25 	"fmt"
     26 	"os"
     27 	"time"
     28 )
     29 
     30 const DEFAULT_C2EC_CONFIG_PATH = "./configs/c2ec-config.yaml" // "c2ec-config.conf"
     31 
     32 // Starts the c2ec process.
     33 // The program takes following arguments (ordered):
     34 //  1. path to configuration file (.yaml | .ini style format) (optional)
     35 //
     36 // The startup follows these steps:
     37 //  1. load configuration or panic
     38 //  2. setup database or panic
     39 //  3. setup provider clients
     40 //  4. setup retrier
     41 //  5. setup attestor
     42 //  6. setup routes for the bank-integration-api
     43 //  7. setup routes for the wire-gateway-api
     44 //  8. listen for incoming requests (as specified in config)
     45 func main() {
     46 
     47 	cfgPath := DEFAULT_C2EC_CONFIG_PATH
     48 	if len(os.Args) > 1 {
     49 
     50 		nextIsConf := false
     51 		for i, arg := range os.Args {
     52 			if i == 0 {
     53 				continue
     54 			} else if nextIsConf {
     55 				cfgPath = arg
     56 				nextIsConf = false
     57 			} else if arg == "-h" {
     58 				helpAndExit("")
     59 			} else if arg == "-c" {
     60 				nextIsConf = true
     61 			} else {
     62 				helpAndExit(arg)
     63 			}
     64 		}
     65 	}
     66 
     67 	utils.LogInfo("main", fmt.Sprintf("starting c2ec at %s", time.Now().Format(time.UnixDate)))
     68 	cfg, err := config.Parse(cfgPath)
     69 	if err != nil {
     70 		panic("unable to load config: " + err.Error())
     71 	}
     72 	if cfg == nil {
     73 		panic("config is nil")
     74 	}
     75 	config.CONFIG = *cfg
     76 
     77 	internal.C2EC()
     78 }
     79 
     80 func helpAndExit(unknownOptionOrEmpty string) {
     81 	if unknownOptionOrEmpty != "" {
     82 		fmt.Println("unkown option provided:", unknownOptionOrEmpty)
     83 	}
     84 	fmt.Println("usage: -h (help) | -c PATH (config file)")
     85 	os.Exit(0)
     86 }