Skip to content

Commit

Permalink
Merge pull request #477 from kube-tarian/agent-gin-fw-rest-server
Browse files Browse the repository at this point in the history
Agent gin fw rest server
  • Loading branch information
share2kanna authored May 3, 2024
2 parents d7ecad2 + 7bd130b commit 9a82e89
Show file tree
Hide file tree
Showing 13 changed files with 618 additions and 203 deletions.
8 changes: 7 additions & 1 deletion capten/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ${OPEN_API_CODEGEN}:

tools: ${OPEN_API_CODEGEN}

OPEN_API_DIR = ./api
OPEN_API_DIR = ./gin-api-server/api/

oapi-gen: tools oapi-gen-deployment-worker

Expand All @@ -20,6 +20,12 @@ oapi-gen-deployment-worker:
@mkdir -p ${APP_NAME}/${OPEN_API_DIR}
${GOBIN}/oapi-codegen -config ./${APP_NAME}/cfg.yaml ./${APP_NAME}/openapi.yaml

oapi-gen-agent: tools
$(eval APP_NAME=agent)
@echo Generating server for ${APP_NAME}
@mkdir -p ${APP_NAME}/${OPEN_API_DIR}
${GOBIN}/oapi-codegen -config ./${APP_NAME}/cfg.yaml ./${APP_NAME}/openapi.yaml

start-docker-compose-test:
docker compose -f ./docker-compose-cass-es.yml up -d --no-recreate
sleep 20
Expand Down
6 changes: 6 additions & 0 deletions capten/agent/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package: api
generate:
gin-server: true
models: true
embedded-spec: true
output: agent/gin-api-server/api/agent.gen.go
266 changes: 266 additions & 0 deletions capten/agent/gin-api-server/api/agent.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions capten/agent/gin-api-server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ginapiserver

import (
"fmt"

"github.com/gin-gonic/gin"
"github.com/intelops/go-common/logging"
"github.com/kube-tarian/kad/capten/agent/gin-api-server/api"
"github.com/kube-tarian/kad/capten/agent/internal/config"
)

var log = logging.NewLogger()

func StartRestServer(rpcapi api.ServerInterface, cfg *config.SericeConfig) {
r := gin.Default()
api.RegisterHandlers(r, rpcapi)

r.Run(fmt.Sprintf("%s:%d", cfg.Host, cfg.RestPort))
}
17 changes: 17 additions & 0 deletions capten/agent/internal/api/basic_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package api

import (
"net/http"

"github.com/gin-gonic/gin"
api "github.com/kube-tarian/kad/capten/agent/gin-api-server/api"
)

// open api swagger documentation
func (a *Agent) GetApiDocs(c *gin.Context) {
apiDocs, err := api.GetSwagger()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
}
c.IndentedJSON(http.StatusOK, apiDocs)
}
Loading

0 comments on commit 9a82e89

Please sign in to comment.