Skip to content

Instantly share code, notes, and snippets.

@bigtan
Last active October 4, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigtan/26c6620c08272269d3e4ddc286d0cb2d to your computer and use it in GitHub Desktop.
Save bigtan/26c6620c08272269d3e4ddc286d0cb2d to your computer and use it in GitHub Desktop.
ss.go
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/riobard/go-shadowsocks2/core"
)
var config struct {
Verbose bool
UDPTimeout time.Duration
}
func logf(f string, v ...interface{}) {
if config.Verbose {
log.Printf(f, v...)
}
}
var settings struct {
Server string `json:"server"`
ServerPort int `json:"server_port"`
LocalPort int `json:"local_port"`
Password string `json:"password"`
Method string `json:"method"`
Timeout int `json:"timeout"`
}
func main() {
configFile, err := os.Open("config.json")
defer configFile.Close()
if err != nil {
log.Fatal(err)
}
jsonParser := json.NewDecoder(configFile)
if err = jsonParser.Decode(&settings); err != nil {
log.Fatal("parsing config file", err.Error())
}
server := fmt.Sprintf("%s:%d", settings.Server, settings.ServerPort)
local := fmt.Sprintf("127.0.0.1:%d", settings.LocalPort)
ciph, err := core.PickCipher(settings.Method, nil, settings.Password)
go socksLocal(local, server, ciph)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment