mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Save meta to explore service (#82)
This commit is contained in:
2
.github/workflows/docs.yml
vendored
2
.github/workflows/docs.yml
vendored
@@ -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'
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user