add templater
This commit is contained in:
2
main.go
2
main.go
@ -33,7 +33,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal("Couldn't create client", err)
|
||||
}
|
||||
if err := client.TBS.RunI2PBWithLang(); err != nil {
|
||||
if err := client.Serve(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -38,13 +38,17 @@ func NewClient(hostname string, lang string, os string, arch string) (*Client, e
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *Client) ServeHTTP(rw http.ResponseWriter, rq http.Request) {
|
||||
func (m *Client) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
|
||||
path := rq.URL.Path
|
||||
switch path {
|
||||
case "/start-tor-browser":
|
||||
m.TBS.RunTBWithLang()
|
||||
case "/start-i2p-browser":
|
||||
m.TBS.RunI2PBWithLang()
|
||||
case "/start-tor":
|
||||
m.TBS.RunTorWithLang()
|
||||
case "/stop-tor":
|
||||
m.TBS.StopTor()
|
||||
default:
|
||||
b, e := m.Page()
|
||||
if e != nil {
|
||||
@ -55,6 +59,11 @@ func (m *Client) ServeHTTP(rw http.ResponseWriter, rq http.Request) {
|
||||
rw.Write([]byte("Hello, world!"))
|
||||
}
|
||||
|
||||
func (m *Client) Serve() error {
|
||||
//http.Handle("/", m)
|
||||
return http.ListenAndServe("127.0.0.1:7695", m)
|
||||
}
|
||||
|
||||
func (m *Client) generateMirrorJSON() (map[string]interface{}, error) {
|
||||
if !strings.HasSuffix(m.hostname, "/") {
|
||||
m.hostname += "/"
|
||||
|
@ -145,19 +145,23 @@ func (s *Supervisor) RunTorWithLang() error {
|
||||
return fmt.Errorf("tor not found at %s", s.TorPath())
|
||||
}
|
||||
case "darwin":
|
||||
cmd := exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
s.cmd = exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
|
||||
s.cmd.Dir = s.TBDirectory()
|
||||
return s.cmd.Run()
|
||||
case "windows":
|
||||
cmd := exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
|
||||
cmd.Dir = s.TBDirectory()
|
||||
return cmd.Run()
|
||||
s.cmd = exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
|
||||
s.cmd.Dir = s.TBDirectory()
|
||||
return s.cmd.Run()
|
||||
default:
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Supervisor) StopTor() error {
|
||||
return s.cmd.Process.Kill()
|
||||
}
|
||||
|
||||
func NewSupervisor(tbPath, lang string) *Supervisor {
|
||||
return &Supervisor{
|
||||
UnpackPath: tbPath,
|
||||
|
Reference in New Issue
Block a user