thestrukture/IDE

View on GitHub
api/handlers/rest_ApiComplete.go

Summary

Maintainability
A
0 mins
Test Coverage
F
30%
// File generated by Gopher Sauce
// DO NOT EDIT!!
package handlers

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "os"
    "path/filepath"
    "strings"

    "github.com/cheikhshift/gos/core"
    "github.com/gorilla/sessions"
    "github.com/thestrukture/IDE/api/globals"
)

//
func ApiComplete(w http.ResponseWriter, r *http.Request, session *sessions.Session) (response string, callmet bool) {

    prefx := r.FormValue("pref")

    content := r.FormValue("content")
    id := r.FormValue("id")
    tempFile := filepath.Join(globals.AutocompletePath, id)

    ioutil.WriteFile(tempFile, []byte(content), 0700)
    cms := "gocode"

    if globals.Windows {
        cms = strings.Replace(os.ExpandEnv("$GOPATH")+"\\bin\\gocode.exe", "/", "\\", -1)

    }

    cmd := fmt.Sprintf(cms+" -f=json -builtin -source --in=%s autocomplete %s", tempFile, prefx)

    res, _ := core.RunCmdSmart(cmd)
    response = res

    os.Remove(tempFile)

    callmet = true
    return
}