Skip to content

Instantly share code, notes, and snippets.

@whyrusleeping
Last active December 16, 2015 16:18
Show Gist options
  • Save whyrusleeping/5461685 to your computer and use it in GitHub Desktop.
Save whyrusleeping/5461685 to your computer and use it in GitHub Desktop.
had a small idea for a build server in go DISCLAIMER: i wrote this without a real text editor off the top of my head, i dont think its gonna compile or work right at all. just ideas
package main
import (
"net"
"gob"
"os"
"bytes"
)
const (
LC = iota
LCpp
LGo
)
type BuildInfo struct {
projectName string
folderData []byte
language int
buildCommand string
exeName string
}
type BuildResults struct {
exe []byte
output []byte
}
func HandleConn(c net.Conn) {
dec := gob.NewDecoder(c)
var info BuildInfo
dec.Decode(&info)
buf := bytes.NewBuffer(info.folderData)
zipp := gzip.NewReader(buf)
f, err := os.Create(info.projectName + ".tar")
//Somehow get all the files in place
os.Chdir(info.projectName)
bc := exec.Command(info.buildCommand)
var results BuildResults
results.output = bc.CombinedOutput()
//Afterwards, send the exe back
f, err := os.Open(info.exeName)
results.exe = ioutil.ReadAll(f)
enc := gob.NewEncoder(c)
enc.Encode(&results)
}
func Listen() {
list, err := net.ListenTCP("tcp", ":8123")
if err != nil {
panic(err)
}
for {
c, _ := list.Accept()
go HandleConn(c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment