Skip to content

Commit

Permalink
Add api for es instance health
Browse files Browse the repository at this point in the history
  • Loading branch information
euiyounghwang committed Jan 2, 2024
1 parent bd16234 commit d8b7dbb
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 74 deletions.
60 changes: 42 additions & 18 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,62 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/swagger_search.Search"
"$ref": "#/definitions/repository.Search"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/swagger_search.Search"
"$ref": "#/definitions/repository.Search"
}
},
"400": {
"description": "We need ID!!",
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/swagger_search.APIError"
"type": "object"
}
},
"404": {
"description": "Can not find ID",
"description": "Not Found",
"schema": {
"$ref": "#/definitions/swagger_search.APIError"
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
}
},
"/health": {
"get": {
"description": "search engine api",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Search"
],
"summary": "search engine api",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
Expand Down Expand Up @@ -135,18 +170,7 @@ const docTemplate = `{
}
}
},
"swagger_search.APIError": {
"type": "object",
"properties": {
"errorCode": {
"type": "integer"
},
"errorMessage": {
"type": "string"
}
}
},
"swagger_search.Search": {
"repository.Search": {
"type": "object",
"properties": {
"age": {
Expand Down
60 changes: 42 additions & 18 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,62 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/swagger_search.Search"
"$ref": "#/definitions/repository.Search"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/swagger_search.Search"
"$ref": "#/definitions/repository.Search"
}
},
"400": {
"description": "We need ID!!",
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/swagger_search.APIError"
"type": "object"
}
},
"404": {
"description": "Can not find ID",
"description": "Not Found",
"schema": {
"$ref": "#/definitions/swagger_search.APIError"
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
}
},
"/health": {
"get": {
"description": "search engine api",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Search"
],
"summary": "search engine api",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
Expand Down Expand Up @@ -124,18 +159,7 @@
}
}
},
"swagger_search.APIError": {
"type": "object",
"properties": {
"errorCode": {
"type": "integer"
},
"errorMessage": {
"type": "string"
}
}
},
"swagger_search.Search": {
"repository.Search": {
"type": "object",
"properties": {
"age": {
Expand Down
44 changes: 30 additions & 14 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ definitions:
example: John
type: string
type: object
swagger_search.APIError:
properties:
errorCode:
type: integer
errorMessage:
type: string
type: object
swagger_search.Search:
repository.Search:
properties:
age:
description: Age
Expand Down Expand Up @@ -63,22 +56,45 @@ paths:
name: search
required: true
schema:
$ref: '#/definitions/swagger_search.Search'
$ref: '#/definitions/repository.Search'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/swagger_search.Search'
$ref: '#/definitions/repository.Search'
"400":
description: We need ID!!
description: Bad Request
schema:
$ref: '#/definitions/swagger_search.APIError'
type: object
"404":
description: Can not find ID
description: Not Found
schema:
type: object
"500":
description: Internal Server Error
schema:
type: object
summary: search engine api
tags:
- Search
/health:
get:
consumes:
- application/json
description: search engine api
produces:
- application/json
responses:
"200":
description: OK
schema:
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/swagger_search.APIError'
type: object
summary: search engine api
tags:
- Search
Expand Down
4 changes: 2 additions & 2 deletions lib/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (


func Set_Env(initial_str string, replace_str string) (string) {
transform_str := ""
transform_str := initial_str
if initial_str == "" {
transform_str = replace_str
}
log.Println("Set_Env : ", transform_str)
return replace_str
return transform_str
}

func ReplaceStr(str string) (string) {
Expand Down
22 changes: 22 additions & 0 deletions repository/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package repository

import "errors"


var (
IndexNameEmptyStringError = errors.New("index name cannot be empty string")
IndexAlreadyExistsError = errors.New("elasticsearch index already exists")
ESInstanceError = errors.New("elasticsearch goes down")
)

type Search struct {
Id int `json:"id" example:"1"` // UserId
Name string `json:"name" example:"John"` // Name
Age int `json:"age" example:"10"` // Age
}


type APIError struct {
ErrorCode int
ErrorMessage string
}
5 changes: 3 additions & 2 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"os"

swagger_search "go-search_engine/swagger_controller"
controller "go-search_engine/swagger_controller"

"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
Expand Down Expand Up @@ -46,7 +46,8 @@ func main() {

v1Search := r.Group("/")
{
v1Search.POST("/es/search", swagger_search.SearchHandler)
v1Search.GET("/health", controller.HealthHandler)
v1Search.POST("/es/search", controller.SearchHandler)
}

httpPort := os.Getenv("PORT")
Expand Down
Loading

0 comments on commit d8b7dbb

Please sign in to comment.