Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit360bed0

Browse files
committed
Implement old storage.Path API
1 parent164e071 commit360bed0

File tree

11 files changed

+44
-39
lines changed

11 files changed

+44
-39
lines changed

‎commands/clear.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ var clearCmd = &cobra.Command{
1313
Use:"clear",
1414
Short:"Clear all user data",
1515
Run:func(cmd*cobra.Command,args []string) {
16-
err:=os.Remove(storage.DataPath.Database())
16+
err:=os.Remove(storage.Path.Database())
1717
iferr==nil||os.IsNotExist(err) {
1818
log.Println("Database cleared")
1919
}else {
2020
log.Println(err)
2121
}
2222

23-
err=os.RemoveAll(storage.DataPath.Users())
23+
err=os.RemoveAll(storage.Path.Users())
2424
iferr==nil {
2525
log.Println("User data cleared")
2626
}else {

‎commands/config.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
Short:"Edit config file",
1717
Run:func(cmd*cobra.Command,args []string) {
1818
ifeditor:=findEditor();editor!="" {
19-
process:=exec.Command(editor,storage.ConfigPath.Config())
19+
process:=exec.Command(editor,storage.Path.Config())
2020
process.Stdin=os.Stdin
2121
process.Stdout=os.Stdout
2222
process.Stderr=os.Stderr

‎commands/dispatch.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ var rootCmd = &cobra.Command{
4646
fmt.Printf(logo,version.Tag,version.Commit,version.Date,runtime.Version())
4747
}
4848

49-
storage.Initialize()
49+
storage.Initialize(viper.GetString("dir"),viper.GetString("data"),viper.GetString("conf"))
5050

51-
initConfig(storage.ConfigPath.Config(),viper.GetBool("reset-config"))
51+
initConfig(storage.Path.Config(),viper.GetBool("reset-config"))
5252
},
5353

5454
Run:func(cmd*cobra.Command,args []string) {
5555
ifviper.GetBool("dev") {
5656
log.Println("Running in development mode, access client at http://localhost:3000")
5757
}
58-
log.Println("Storing data at",storage.DataPath.Root())
58+
log.Println("Storing data at",storage.Path.DataRoot())
5959

60-
db,err:=boltdb.New(storage.DataPath.Database())
60+
db,err:=boltdb.New(storage.Path.Database())
6161
iferr!=nil {
6262
log.Fatal(err)
6363
}
@@ -77,11 +77,11 @@ var rootCmd = &cobra.Command{
7777
dispatch.SessionStore=db
7878

7979
dispatch.GetMessageStore=func(user*storage.User) (storage.MessageStore,error) {
80-
returnboltdb.New(storage.DataPath.Log(user.Username))
80+
returnboltdb.New(storage.Path.Log(user.Username))
8181
}
8282

8383
dispatch.GetMessageSearchProvider=func(user*storage.User) (storage.MessageSearchProvider,error) {
84-
returnbleve.New(storage.DataPath.Index(user.Username))
84+
returnbleve.New(storage.Path.Index(user.Username))
8585
}
8686

8787
dispatch.Run()

‎config/config.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type LetsEncrypt struct {
5353

5454
funcLoadConfig() (*Config,chan*Config) {
5555
viper.SetConfigName("config")
56-
viper.AddConfigPath(storage.ConfigPath.Root())
56+
viper.AddConfigPath(storage.Path.ConfigRoot())
5757
viper.ReadInConfig()
5858

5959
config:=&Config{}

‎server/irc_handler_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
2222
log.Fatal(err)
2323
}
2424

25-
storage.Initialize(tempdir)
25+
storage.Initialize(tempdir,"","")
2626

2727
db,err:=boltdb.New(storage.Path.Database())
2828
iferr!=nil {

‎server/server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (d *Dispatch) startHTTP() {
147147
PortHTTPS:cfg.HTTPS.Port,
148148
HTTPOnly:!cfg.HTTPS.Enabled,
149149

150-
StoragePath:storage.ConfigPath.LetsEncrypt(),
150+
StoragePath:storage.Path.LetsEncrypt(),
151151
Domain:cfg.LetsEncrypt.Domain,
152152
Email:cfg.LetsEncrypt.Email,
153153

‎storage/directory.go‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,33 @@ package storage
33
import (
44
"path/filepath"
55

6-
"github.com/mitchellh/go-homedir"
6+
homedir"github.com/mitchellh/go-homedir"
77
)
88

99
funcDefaultDirectory()string {
1010
home,_:=homedir.Dir()
1111
returnfilepath.Join(home,".dispatch")
1212
}
1313

14-
typedirectorystring
14+
typedirectorystruct {
15+
dataRootstring
16+
configRootstring
17+
}
18+
19+
func (ddirectory)DataRoot()string {
20+
returnd.dataRoot
21+
}
1522

16-
func (ddirectory)Root()string {
17-
returnstring(d)
23+
func (ddirectory)ConfigRoot()string {
24+
returnd.configRoot
1825
}
1926

2027
func (ddirectory)LetsEncrypt()string {
21-
returnfilepath.Join(d.Root(),"letsencrypt")
28+
returnfilepath.Join(d.ConfigRoot(),"letsencrypt")
2229
}
2330

2431
func (ddirectory)Users()string {
25-
returnfilepath.Join(d.Root(),"users")
32+
returnfilepath.Join(d.DataRoot(),"users")
2633
}
2734

2835
func (ddirectory)User(usernamestring)string {
@@ -46,9 +53,9 @@ func (d directory) Key(username string) string {
4653
}
4754

4855
func (ddirectory)Config()string {
49-
returnfilepath.Join(d.Root(),"config.toml")
56+
returnfilepath.Join(d.ConfigRoot(),"config.toml")
5057
}
5158

5259
func (ddirectory)Database()string {
53-
returnfilepath.Join(d.Root(),"dispatch.db")
60+
returnfilepath.Join(d.DataRoot(),"dispatch.db")
5461
}

‎storage/storage.go‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ import (
55
"os"
66

77
"github.com/khlieng/dispatch/pkg/session"
8-
"github.com/spf13/viper"
98
)
109

11-
varDataPathdirectory
12-
varConfigPathdirectory
10+
varPathdirectory
1311

14-
funcInitialize() {
15-
ifviper.GetString("dir")!=DefaultDirectory() {
16-
DataPath=directory(viper.GetString("dir"))
17-
ConfigPath=directory(viper.GetString("dir"))
12+
funcInitialize(root,dataRoot,configRootstring) {
13+
ifroot!=DefaultDirectory() {
14+
Path.dataRoot=root
15+
Path.configRoot=root
1816
}else {
19-
DataPath=directory(viper.GetString("data"))
20-
ConfigPath=directory(viper.GetString("conf"))
17+
Path.dataRoot=dataRoot
18+
Path.configRoot=configRoot
2119
}
22-
os.MkdirAll(DataPath.Root(),0700)
23-
os.MkdirAll(ConfigPath.Root(),0700)
20+
os.MkdirAll(Path.DataRoot(),0700)
21+
os.MkdirAll(Path.ConfigRoot(),0700)
2422
}
2523

2624
var (

‎storage/user.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewUser(store Store) (*User, error) {
3232
returnnil,err
3333
}
3434

35-
err=os.MkdirAll(DataPath.User(user.Username),0700)
35+
err=os.MkdirAll(Path.User(user.Username),0700)
3636
iferr!=nil {
3737
returnnil,err
3838
}
@@ -70,7 +70,7 @@ func (u *User) Remove() {
7070
ifu.messageIndex!=nil {
7171
u.messageIndex.Close()
7272
}
73-
os.RemoveAll(DataPath.User(u.Username))
73+
os.RemoveAll(Path.User(u.Username))
7474
}
7575

7676
func (u*User)GetLastIP() []byte {

‎storage/user_cert.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func (u *User) SetCertificate(certPEM, keyPEM []byte) error {
2828
u.certificate=&cert
2929
u.lock.Unlock()
3030

31-
err=ioutil.WriteFile(ConfigPath.Certificate(u.Username),certPEM,0600)
31+
err=ioutil.WriteFile(Path.Certificate(u.Username),certPEM,0600)
3232
iferr!=nil {
3333
returnErrCouldNotSaveCert
3434
}
3535

36-
err=ioutil.WriteFile(ConfigPath.Key(u.Username),keyPEM,0600)
36+
err=ioutil.WriteFile(Path.Key(u.Username),keyPEM,0600)
3737
iferr!=nil {
3838
returnErrCouldNotSaveCert
3939
}
@@ -42,12 +42,12 @@ func (u *User) SetCertificate(certPEM, keyPEM []byte) error {
4242
}
4343

4444
func (u*User)loadCertificate()error {
45-
certPEM,err:=ioutil.ReadFile(ConfigPath.Certificate(u.Username))
45+
certPEM,err:=ioutil.ReadFile(Path.Certificate(u.Username))
4646
iferr!=nil {
4747
returnerr
4848
}
4949

50-
keyPEM,err:=ioutil.ReadFile(ConfigPath.Key(u.Username))
50+
keyPEM,err:=ioutil.ReadFile(Path.Key(u.Username))
5151
iferr!=nil {
5252
returnerr
5353
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp