-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement REST API to provide settings to the frontend, as defined in…
… openapi spec and unmarshalled from the config file
- Loading branch information
Showing
6 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# logstation API | ||
|
||
The logstation API provides access to restful actions for the logstation UI. All the logs go over the websocket, but certain things like the syntax colors are queried via REST, which this API provides. | ||
|
||
## Building | ||
The REST API is codegen'd on the server and client side through [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator). | ||
|
||
### Generate API Server | ||
Install the openapi-generator and run the following in the `logstation` root folder: | ||
``` | ||
java -jar .\openapi-generator-cli.jar generate -i .\api\logstation-rest-api.yaml -g go-echo-server -o api\server --additional-properties hideGenerationTimestamp=true | ||
``` | ||
This will create a `logstation/api/server` folder which gets imported into `main.go`. | ||
> Note: You may need to remove the `go.mod` after codegen so go doesn't treat `api/server` as it's own go module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/jdrews/logstation/api/server/models" | ||
"github.com/labstack/echo/v4" | ||
"github.com/spf13/viper" | ||
"net/http" | ||
) | ||
|
||
// GetLogstationName - Get Logstation Name | ||
func (c *Container) GetLogstationName(ctx echo.Context) error { | ||
return ctx.JSON(http.StatusOK, models.LogstationName{ | ||
Name: viper.GetString("logStationName"), | ||
}) | ||
} | ||
|
||
// GetSettingsSyntax - Get Syntax Colors | ||
func (c *Container) GetSettingsSyntax(ctx echo.Context) error { | ||
var syntaxColors models.SyntaxColors | ||
viper.UnmarshalKey("syntaxColors", &syntaxColors) | ||
return ctx.JSON(http.StatusOK, syntaxColors) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package handlers | ||
|
||
// Container will hold all dependencies for your application. | ||
type Container struct { | ||
} | ||
|
||
// NewContainer returns an empty or an initialized container for your handlers. | ||
func NewContainer() (Container, error) { | ||
c := Container{} | ||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package models | ||
|
||
// LogstationName - | ||
type LogstationName struct { | ||
|
||
// Name of the logstation server | ||
Name string `json:"name"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package models | ||
|
||
// SyntaxColor - A syntax color and regex string for highlighting text | ||
type SyntaxColor struct { | ||
Color string `json:"color,omitempty"` | ||
|
||
Regex string `json:"regex,omitempty"` | ||
} | ||
|
||
// SyntaxColors - An array/slice of syntax colors | ||
type SyntaxColors []SyntaxColor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters