Save meta to explore service (#82)

This commit is contained in:
Janos Dobronszki
2021-04-27 10:39:03 +01:00
committed by GitHub
parent 83a147a27b
commit 2c8708ad65
2 changed files with 38 additions and 0 deletions

View File

@@ -58,6 +58,8 @@ jobs:
working-directory: services working-directory: services
run: | run: |
go run cmd/docgen/main.go . go run cmd/docgen/main.go .
env:
MICRO_ADMIN_TOKEN: ${{ secrets.MICRO_ADMIN_TOKEN }}
- name: Deploy - name: Deploy
if: github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'

View File

@@ -1,11 +1,13 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -16,6 +18,33 @@ import (
"github.com/stoewer/go-strcase" "github.com/stoewer/go-strcase"
) )
func saveMeta(service, readme, openapijson string) error {
client := &http.Client{}
//Encode the data
postBody, _ := json.Marshal(map[string]string{
"serviceName": service,
"readme": readme,
"openAPIJSON": openapijson,
})
rbody := bytes.NewBuffer(postBody)
//Leverage Go's HTTP Post function to make request
req, err := http.NewRequest("POST", "https://api.m3o.com/explore/SaveMeta", rbody)
// Add auth headers here if needed
req.Header.Add("Authorization", `Bearer `+os.Getenv("MICRO_ADMIN_TOKEN"))
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
io.Copy(ioutil.Discard, resp.Body)
return nil
}
const ( const (
postContentPath = "docs/hugo-tania/site/content/post" postContentPath = "docs/hugo-tania/site/content/post"
docsURL = "services.m3o.com" docsURL = "services.m3o.com"
@@ -92,6 +121,13 @@ func main() {
fmt.Println("Failed to unmarshal", err) fmt.Println("Failed to unmarshal", err)
os.Exit(1) os.Exit(1)
} }
err = saveMeta(serviceName, string(dat), string(js))
if err != nil {
fmt.Println("Failed to save meta to explore service", err)
os.Exit(1)
}
err = saveSpec(dat, contentDir, serviceName, spec) err = saveSpec(dat, contentDir, serviceName, spec)
if err != nil { if err != nil {
fmt.Println("Failed to save to spec file", err) fmt.Println("Failed to save to spec file", err)