Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cbb6d9

Browse filesBrowse files
committed
add support for config file
1 parent a1af8bd commit 7cbb6d9
Copy full SHA for 7cbb6d9

File tree

Expand file treeCollapse file tree

4 files changed

+27
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-3
lines changed

‎collector/config.go

Copy file name to clipboardExpand all lines: collector/config.go
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import (
66
"github.com/pkg/errors"
77
"io/ioutil"
88
"os"
9+
"path"
910
"strings"
1011

1112
"github.com/howeyc/gopass"
13+
"github.com/jinzhu/configor"
1214
"github.com/realzhangm/leetcode_collector/collector/leetcode_cli"
1315
)
1416

1517
type Config struct {
1618
ltClientConf leetcode_cli.ClientConf
1719
SolutionsDir string
18-
OutputDir string
20+
OutputDir string `default:"./output"`
1921
initFlag bool
2022
}
2123

@@ -35,8 +37,20 @@ func init() {
3537
}
3638

3739
func LoadConfig() {
38-
config.SolutionsDir = "./output/solutions"
39-
config.OutputDir = "./output"
40+
// file not exist, no error return
41+
err := configor.Load(&config, "config.toml")
42+
if err != nil {
43+
fmt.Println("---------------")
44+
panic(err)
45+
}
46+
47+
if config.OutputDir == "" {
48+
config.OutputDir = "./output"
49+
}
50+
51+
if config.SolutionsDir == "" {
52+
config.SolutionsDir = path.Join(config.OutputDir, "solutions")
53+
}
4054

4155
if loadPass() != nil {
4256
var err error

‎config.toml

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OutputDir = 'C:\Users\ingm\Desktop\code\github\leetcode_sync'

‎go.mod

Copy file name to clipboardExpand all lines: go.mod
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/gobwas/glob v0.2.3 // indirect
1010
github.com/gocolly/colly v1.2.0
1111
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
12+
github.com/jinzhu/configor v1.2.1
1213
github.com/kennygrant/sanitize v1.2.4 // indirect
1314
github.com/machinebox/graphql v0.2.2
1415
github.com/matryer/is v1.4.0 // indirect

‎go.sum

Copy file name to clipboardExpand all lines: go.sum
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
13
github.com/PuerkitoBio/goquery v1.7.1 h1:oE+T06D+1T7LNrn91B4aERsRIeCLJ/oPSa6xB9FPnz4=
24
github.com/PuerkitoBio/goquery v1.7.1/go.mod h1:XY0pP4kfraEmmV1O7Uf6XyjoslwsneBbgeDjLYuN8xY=
35
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
@@ -20,6 +22,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
2022
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2123
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM=
2224
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
25+
github.com/jinzhu/configor v1.2.1 h1:OKk9dsR8i6HPOCZR8BcMtcEImAFjIhbJFZNyn5GCZko=
26+
github.com/jinzhu/configor v1.2.1/go.mod h1:nX89/MOmDba7ZX7GCyU/VIaQ2Ar2aizBl2d3JLF/rDc=
2327
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
2428
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
2529
github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo=
@@ -64,3 +68,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
6468
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6569
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
6670
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
71+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
72+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
73+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
74+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.