Skip to content

Instantly share code, notes, and snippets.

View abhirockzz's full-sized avatar
👋
fmt.Println(hello, world!)

Abhishek Gupta abhirockzz

👋
fmt.Println(hello, world!)
View GitHub Profile
....
var criteria SearchCriteria
json.NewDecoder(in).Decode(&criteria)
cmpt := criteria.CompartmentIDFilter
instances := []Instance{}
resp, err := cc.ListInstances(context.Background(), core.ListInstancesRequest{CompartmentId: common.String(cmpt)})
for _, instance := range resp.Items {
....
tenancy := os.Getenv("TENANT_OCID")
user := os.Getenv("USER_OCID")
region := os.Getenv("REGION")
fingerprint := os.Getenv("FINGERPRINT")
privateKeyName := os.Getenv("OCI_PRIVATE_KEY_FILE_NAME")
privateKeyLocation := privateKeyFolder + "/" + privateKeyName
passphrase := os.Getenv("PASSPHRASE")
privateKey, err := ioutil.ReadFile(privateKeyLocation)
....
FROM fnproject/go:dev as build-stage
WORKDIR /function
RUN go get -u github.com/golang/dep/cmd/dep
ADD . /go/src/func/
RUN cd /go/src/func/ && dep ensure
RUN cd /go/src/func/ && go build -o func
FROM fnproject/go
RUN apk add --no-cache flite
WORKDIR /function
speech, err := ioutil.ReadFile(outputLocation)
if err != nil {
errMsg := "could not read from .wav file " + err.Error()
log.Println(errMsg)
out.Write([]byte(errMsg))
return
}
log.Println("Returning .wav bytes")
defer func() {
fileErr := os.Remove(outputLocation)
if fileErr == nil {
log.Println("Deleted temp file", outputLocation)
} else {
log.Println("Error removing output file", fileErr.Error())
}
}()
...
flite := exec.Command("flite", "-t", text, "-o", outputLocation)
err := flite.Run()
if err != nil {
errMsg := "failed due to " + err.Error()
log.Println(errMsg)
out.Write([]byte(errMsg))
return
}
...
func main() {
fdk.Handle(fdk.HandlerFunc(text2speech))
}
func text2speech(ctx context.Context, in io.Reader, out io.Writer) {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
text := buf.String()
....
slackResponse := SlackResponse{Text: slackResponseStaticText, Attachments: []Attachment{Attachment{Text: title, ImageURL: url}}}
fdk.AddHeader(out, "Content-Type", "application/json")
json.NewEncoder(out).Encode(slackResponse)
...
giphyResp, err := http.Get("http://api.giphy.com/v1/gifs/random?tag=" + giphyTag + "&api_key=" + apiKey)
if err != nil {
fmt.Println("giphy did not respond", err)
return
}
resp, err := ioutil.ReadAll(giphyResp.Body)
if err != nil {
fmt.Println("could not read giphy resp", err)
...
vals, err := parse(b)
if err != nil {
fmt.Println("unable to parse data sent by slack", err)
}
giphyTag := vals.Get("text")
...
func parse(b []byte) (url.Values, error) {
vals, e := url.ParseQuery(string(b))
if e != nil {