View fn-oci-compute-3.go
.... | |
var updateInfo UpdateInfo | |
json.NewDecoder(in).Decode(&updateInfo) | |
_, err := cc.UpdateInstance(context.Background(), core.UpdateInstanceRequest{InstanceId: common.String(updateInfo.OCID), UpdateInstanceDetails: core.UpdateInstanceDetails{DisplayName: common.String(updateInfo.NewDisplayName)}}) | |
.... |
View fn-oci-compute-2.go
.... | |
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 { |
View fn-oci-compute-1.go
.... | |
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) | |
.... |
View text-to-speech-Dockerfile
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 |
View text-to-speech-4.go
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") |
View text-to-speech-3.go
defer func() { | |
fileErr := os.Remove(outputLocation) | |
if fileErr == nil { | |
log.Println("Deleted temp file", outputLocation) | |
} else { | |
log.Println("Error removing output file", fileErr.Error()) | |
} | |
}() |
View text-to-speech-2.go
... | |
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 | |
} | |
... |
View text-to-speech-1.go
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() | |
.... |
View funcy-6.go
slackResponse := SlackResponse{Text: slackResponseStaticText, Attachments: []Attachment{Attachment{Text: title, ImageURL: url}}} | |
fdk.AddHeader(out, "Content-Type", "application/json") | |
json.NewEncoder(out).Encode(slackResponse) |
View funcy-4.go
... | |
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 { |