stevef1uk / openfaas-go-handler

OpenFaas test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenFaas Go Handler

OpenFaas test Contains a simple Go handler which can be deployed as an OpenFaaS function. The function handles GET & POST methiods and in this case route the request to test4, which is an automatically generated function (from cassuservice) that reads or writes to a Cassandra table depending upon whether a GET or POST.

Recently added a secret & associated API Key to validate that the request is trusted.

The functional can be invoked for READ via the OpenFaaS GUI at https://system.sjfisher.com/dashboard/stevef1uk however, it won't work as the API Key needs to be passed. Thus using curl is required follows:


 curl  -H "X-Api-Key: I'mSteveLetMeIn" -v  https://stevef1uk.sjfisher.com/go1?id=1
  curl -d '{"id": 3, "message": "Sarah"}' -H "Content-Type: application/json" -H "X-Api-Key: I'mSteveLetMeIn" -v -X POST https://stevef1uk.sjfisher.com/go1

Of course as OpenFaaS support asynchronous function execution (using NATS) it is possible to use an alternative URL to achive this:


curl -d '{"id": 10, "message": "Async Test"}' -H "Content-Type: application/json" -H "X-Api-Key: I'mSteveLetMeIn" -v -X POST https://gw.sjfisher.com/async-function/stevef1uk-go1

Alternatively the OpenFaaS Gateway GUI can be used: https://gw.sjfisher.com/ui/ To deploy the Gateway I followed the ofc_bootstrap approach to deploy OpenFaaS Private Cloud and then applied the following yaml:


apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 name: openfaas-gw-ingress
 annotations:
  kubernetes.io/ingress.class: "nginx"
  cert-manager.io/issuer: letsencrypt-prod
spec:
 tls:
  - hosts:
    - gw.<>
   secretName: openfaas-crt
 hosts:
  - host: gw.<>
   serviceName: gateway
   servicePort: 8080
   path: /
 rules:
  - host: gw.<>
   http:
    paths:
    - path: /
     backend:
      serviceName: gateway
      servicePort: 8080

About

OpenFaas test


Languages

Language:Go 100.0%