-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from rarimo/add-maintenance
Add maintenance
- Loading branch information
Showing
13 changed files
with
168 additions
and
4 deletions.
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
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
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,15 @@ | ||
allOf: | ||
- $ref: '#/components/schemas/MaintenanceKey' | ||
- type: object | ||
required: | ||
- attributes | ||
properties: | ||
attributes: | ||
type: object | ||
required: | ||
- maintenance | ||
properties: | ||
maintenance: | ||
type: bool | ||
example: false | ||
description: "true if the service is under maintenance and false otherwise." |
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,7 @@ | ||
type: object | ||
required: | ||
- type | ||
properties: | ||
type: | ||
type: string | ||
enum: [ maintenance ] |
18 changes: 18 additions & 0 deletions
18
docs/spec/paths/integrations@rarime-points-svc@v1@public@maintenance.yaml
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,18 @@ | ||
get: | ||
tags: | ||
- Maintenance | ||
summary: Get maintenance status | ||
description: Returns true if the service is under maintenance and false otherwise. | ||
operationId: getMaintenanceStatus | ||
responses: | ||
200: | ||
description: Success | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/Maintenance' |
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
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,27 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gitlab.com/distributed_lab/figure/v3" | ||
"gitlab.com/distributed_lab/kit/kv" | ||
) | ||
|
||
type Maintenance struct { | ||
IsMaintenance bool `fig:"is_maintenance"` | ||
} | ||
|
||
func (c *config) Maintenance() Maintenance { | ||
return c.maintenance.Do(func() interface{} { | ||
var cfg Maintenance | ||
|
||
err := figure.Out(&cfg). | ||
From(kv.MustGetStringMap(c.getter, "maintenance")). | ||
Please() | ||
if err != nil { | ||
panic(fmt.Errorf("failed to figure out is_maintenance: %w", err)) | ||
} | ||
|
||
return cfg | ||
}).(Maintenance) | ||
} |
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
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,21 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/rarimo/rarime-points-svc/resources" | ||
"gitlab.com/distributed_lab/ape" | ||
) | ||
|
||
func MaintenanceHandler(w http.ResponseWriter, r *http.Request) { | ||
ape.Render(w, resources.MaintenanceResponse{ | ||
Data: resources.Maintenance{ | ||
Key: resources.Key{ | ||
Type: resources.MAINTENANCE, | ||
}, | ||
Attributes: resources.MaintenanceAttributes{ | ||
Maintenance: MaintenanceConfig(r).IsMaintenance, | ||
}, | ||
}, | ||
}) | ||
} |
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
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,43 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
import "encoding/json" | ||
|
||
type Maintenance struct { | ||
Key | ||
Attributes MaintenanceAttributes `json:"attributes"` | ||
} | ||
type MaintenanceResponse struct { | ||
Data Maintenance `json:"data"` | ||
Included Included `json:"included"` | ||
} | ||
|
||
type MaintenanceListResponse struct { | ||
Data []Maintenance `json:"data"` | ||
Included Included `json:"included"` | ||
Links *Links `json:"links"` | ||
Meta json.RawMessage `json:"meta,omitempty"` | ||
} | ||
|
||
func (r *MaintenanceListResponse) PutMeta(v interface{}) (err error) { | ||
r.Meta, err = json.Marshal(v) | ||
return err | ||
} | ||
|
||
func (r *MaintenanceListResponse) GetMeta(out interface{}) error { | ||
return json.Unmarshal(r.Meta, out) | ||
} | ||
|
||
// MustMaintenance - returns Maintenance from include collection. | ||
// if entry with specified key does not exist - returns nil | ||
// if entry with specified key exists but type or ID mismatches - panics | ||
func (c *Included) MustMaintenance(key Key) *Maintenance { | ||
var maintenance Maintenance | ||
if c.tryFindEntry(key, &maintenance) { | ||
return &maintenance | ||
} | ||
return 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,10 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
type MaintenanceAttributes struct { | ||
// true if the service is under maintenance and false otherwise. | ||
Maintenance bool `json:"maintenance"` | ||
} |
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