-
Notifications
You must be signed in to change notification settings - Fork 2
/
banking.go
52 lines (46 loc) · 1.21 KB
/
banking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package banking
import (
"encoding/json"
"errors"
"io/ioutil"
"github.com/binzume/gobanking/common"
"github.com/binzume/gobanking/mizuho"
"github.com/binzume/gobanking/rakuten"
"github.com/binzume/gobanking/sbi"
"github.com/binzume/gobanking/shinsei"
"github.com/binzume/gobanking/stub"
)
type AccountConfig struct {
Bank string `json:"bank"`
Id string `json:"id"`
Password string `json:"password"`
Options map[string]interface{} `json:"options"`
}
func LoginWithJsonFile(path string) (common.Account, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var c AccountConfig
err = json.Unmarshal(buf, &c)
if err != nil {
return nil, err
}
return Login(&c)
}
func Login(c *AccountConfig) (common.Account, error) {
switch c.Bank {
case "mizuho":
return mizuho.Login(c.Id, c.Password, c.Options)
case "rakuten":
return rakuten.Login(c.Id, c.Password, c.Options)
case "shinsei":
return shinsei.Login(c.Id, c.Password, c.Options)
case "sbi":
return sbi.Login(c.Id, c.Password, c.Options)
case "stub":
return stub.Login(c.Id, c.Password, c.Options)
default:
return nil, errors.New("unknown:" + c.Bank)
}
}