setup parser

This commit is contained in:
Carlosokumu 2024-08-31 10:21:20 +03:00
parent ef0c207fc4
commit cc323707fc
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953
2 changed files with 20 additions and 10 deletions

View File

@ -83,7 +83,11 @@ func main() {
fp := path.Join(dp, sessionId)
ussdHandlers := ussd.NewHandlers(fp, &st)
ussdHandlers,err := ussd.NewHandlers(fp, &st)
if(err != nil){
fmt.Fprintf(os.Stderr, "handler setup failed with error: %v\n", err)
}
rfs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
rfs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)

View File

@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"git.defalsify.org/vise.git/asm"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/lang"
"git.defalsify.org/vise.git/resource"
@ -29,25 +30,30 @@ type FSData struct {
St *state.State
}
type Handlers struct {
fs *FSData
parser *asm.FlagParser
accountFileHandler utils.AccountFileHandlerInterface
accountService server.AccountServiceInterface
}
func NewHandlers(path string, st *state.State) *Handlers {
func NewHandlers(dir string, st *state.State) (*Handlers, error) {
pfp := path.Join(dir, "pp.csv")
parser := asm.NewFlagParser()
_, err := parser.Load(pfp)
if err != nil {
return nil, err
}
return &Handlers{
fs: &FSData{
Path: path,
Path: dir,
St: st,
},
accountFileHandler: utils.NewAccountFileHandler(path + "_data"),
parser: parser,
accountFileHandler: utils.NewAccountFileHandler(dir + "_data"),
accountService: &server.AccountService{},
}, nil
}
}
// Define the regex pattern as a constant
const pinPattern = `^\d{4}$`