forked from urdt/ussd
setup parser
This commit is contained in:
parent
ef0c207fc4
commit
cc323707fc
@ -83,7 +83,11 @@ func main() {
|
|||||||
|
|
||||||
fp := path.Join(dp, sessionId)
|
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("select_language", ussdHandlers.SetLanguage)
|
||||||
rfs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
rfs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/lang"
|
"git.defalsify.org/vise.git/lang"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
@ -29,26 +30,31 @@ type FSData struct {
|
|||||||
St *state.State
|
St *state.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Handlers struct {
|
type Handlers struct {
|
||||||
fs *FSData
|
fs *FSData
|
||||||
|
parser *asm.FlagParser
|
||||||
accountFileHandler utils.AccountFileHandlerInterface
|
accountFileHandler utils.AccountFileHandlerInterface
|
||||||
accountService server.AccountServiceInterface
|
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{
|
return &Handlers{
|
||||||
fs: &FSData{
|
fs: &FSData{
|
||||||
Path: path,
|
Path: dir,
|
||||||
St: st,
|
St: st,
|
||||||
},
|
},
|
||||||
accountFileHandler: utils.NewAccountFileHandler(path + "_data"),
|
parser: parser,
|
||||||
|
accountFileHandler: utils.NewAccountFileHandler(dir + "_data"),
|
||||||
accountService: &server.AccountService{},
|
accountService: &server.AccountService{},
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Define the regex pattern as a constant
|
// Define the regex pattern as a constant
|
||||||
const pinPattern = `^\d{4}$`
|
const pinPattern = `^\d{4}$`
|
||||||
|
|
||||||
@ -191,7 +197,7 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//codeFromCtx retrieves language codes from the context that can be used for handling translations
|
// codeFromCtx retrieves language codes from the context that can be used for handling translations
|
||||||
func codeFromCtx(ctx context.Context) string {
|
func codeFromCtx(ctx context.Context) string {
|
||||||
var code string
|
var code string
|
||||||
engine.Logg.DebugCtxf(ctx, "in msg", "ctx", ctx, "val", code)
|
engine.Logg.DebugCtxf(ctx, "in msg", "ctx", ctx, "val", code)
|
||||||
|
Loading…
Reference in New Issue
Block a user