12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package aroz
- import (
- "encoding/json"
- "flag"
- "fmt"
- "net/http"
- "net/url"
- "os"
- )
- type ArozHandler struct {
- Port string
- restfulEndpoint string
- }
- type ServiceInfo struct {
- Name string
- Desc string
- Group string
- IconPath string
- Version string
- StartDir string
- SupportFW bool
- LaunchFWDir string
- SupportEmb bool
- LaunchEmb string
- InitFWSize []int
- InitEmbSize []int
- SupportedExt []string
- }
- func HandleFlagParse(info ServiceInfo) *ArozHandler {
- var infoRequestMode = flag.Bool("info", false, "Show information about this subservice")
- var port = flag.String("port", ":8000", "The default listening endpoint for this subservice")
- var restful = flag.String("rpt", "http://localhost:8080/api/ajgi/interface", "The RESTFUL Endpoint of the parent")
-
- flag.Parse()
- if *infoRequestMode == true {
-
- jsonString, _ := json.Marshal(info)
- fmt.Println(string(jsonString))
- os.Exit(0)
- }
- return &ArozHandler{
- Port: *port,
- restfulEndpoint: *restful,
- }
- }
- func (a *ArozHandler) GetUserInfoFromRequest(w http.ResponseWriter, r *http.Request) (string, string) {
- username := r.Header.Get("aouser")
- token := r.Header.Get("aotoken")
- return username, token
- }
- func (a *ArozHandler) RequestGatewayInterface(token string, script string) (*http.Response, error) {
- resp, err := http.PostForm(a.restfulEndpoint,
- url.Values{"token": {token}, "script": {script}})
- if err != nil {
-
- return nil, err
- }
- return resp, nil
- }
|