-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Server":"127.0.0.1", | ||
"ServerPort":8388, | ||
"LocalPort":1080, | ||
"Password":"barfoo!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: clowwindy | ||
* Date: 12-11-2 | ||
* Time: 上午10:31 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
package shadowsocks | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"log" | ||
) | ||
type Config struct { | ||
Server string | ||
ServerPort int | ||
LocalPort int | ||
Password string | ||
} | ||
|
||
func ParseConfig() Config { | ||
file, err := os.Open("config.json") // For read access. | ||
if err != nil { | ||
log.Fatal("error opening config file config.json:", err) | ||
} | ||
data := make([]byte, 4096) | ||
count, err := file.Read(data) | ||
if err != nil { | ||
log.Fatal("error reading config:", err) | ||
} | ||
if count == 4096 { | ||
log.Fatal("config file is too large") | ||
} | ||
var config Config | ||
err = json.Unmarshal(data[0:count], &config) | ||
if err != nil { | ||
log.Fatal("can not parse config:",err) | ||
} | ||
return config | ||
} |