-
Notifications
You must be signed in to change notification settings - Fork 0
/
milieu.go
49 lines (43 loc) · 955 Bytes
/
milieu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2015 YP LLC.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)
func main() {
http.HandleFunc("/", preview)
log.Fatal(http.ListenAndServe(":80", nil))
}
func env() string {
environment, err := shPipe("env", "sort")
if err != nil {
fmt.Println(err)
}
return environment
}
func shPipe(first string, second string) (string, error) {
c1 := exec.Command(first)
c2 := exec.Command(second)
c2.Stdin, _ = c1.StdoutPipe()
var out bytes.Buffer
c2.Stdout = &out
_ = c2.Start()
err := c1.Run()
_ = c2.Wait()
return strings.Trim(out.String(), " \n"), err
}
func preview(w http.ResponseWriter, r *http.Request) {
r.Write(w)
env, err := shPipe("env", "sort")
if err != nil {
fmt.Println(err)
}
fmt.Fprintln(w, env+"\n")
fmt.Fprintln(w, "Open sourced by YP LLC. http://engineering.yp.com")
}