Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • fb6-wp11-devops/webservice
  • maha1056/devops-pipeline
  • ludo8147/webservice
  • s52888/webservice
  • masi9606/webservice
  • kibu5600/webservice
  • s78689/webservice
  • s50860/webservice
  • s92604/devops-webservice
  • s76867/webservice-devops
  • s92274/webservice
  • s80066/webservice
  • masa1998/webservice
  • s91190/app-service
  • s84985/webservice
  • s75359/webservice
  • ouch4861/webservice-ws-24-oc
  • s92274/webservice-msws-24
  • ewbo4360/webservice
19 results
Show changes
Commits on Source (4)
...@@ -37,6 +37,7 @@ $(BIN_DIR)/artifact.bin: ...@@ -37,6 +37,7 @@ $(BIN_DIR)/artifact.bin:
cd $(SRC_DIR) \ cd $(SRC_DIR) \
&& go build \ && go build \
-o $(@) \ -o $(@) \
-ldflags "-X webservice/configuration.version=0.0.1" \
$(SRC_DIR)/*.go $(SRC_DIR)/*.go
.PHONY: build-linux .PHONY: build-linux
......
...@@ -24,9 +24,11 @@ information checkout the [configuration code](./configuration/config.go). ...@@ -24,9 +24,11 @@ information checkout the [configuration code](./configuration/config.go).
3. Execute unit tests: `go test -race -v ./...` 3. Execute unit tests: `go test -race -v ./...`
4. Build artifact: `go build -o ./artifact.bin ./*.go` 4. Build artifact: `go build -o ./artifact.bin ./*.go`
To build for another platform, set `GOOS` and `GOARCH`. To yield a static binary (fully To build for another platform, set `GOOS` and `GOARCH`. To yield a static
self-contained, no dynamic linking) set `CGO_ENABLED=0`. For more details, please refer binary (fully self-contained, no dynamic linking) set `CGO_ENABLED=0`.
to the [Makefile](./Makefile). To set a version during build time, add the following CLI option
`-ldflags "-X webservice/configuration.version=${VERSION}"`.
For more information, please refer to the [Makefile](./Makefile).
#### Run: #### Run:
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"unicode"
fp "path/filepath" fp "path/filepath"
configParser "github.com/caarlos0/env/v9" configParser "github.com/caarlos0/env/v9"
...@@ -12,9 +13,13 @@ import ( ...@@ -12,9 +13,13 @@ import (
const BODY_SIZE_LIMIT = 32 * 1024 * 1024 // 32 MB, in bytes const BODY_SIZE_LIMIT = 32 * 1024 * 1024 // 32 MB, in bytes
var version string = "n/a"
type Config struct { type Config struct {
Version string `env:"VERSION" envDefault:"N/A"` Version string
FontColor string `env:"FONT_COLOR" envDefault:""`
LogLevel string `env:"LOG_LEVE" envDefault:"error"` LogLevel string `env:"LOG_LEVE" envDefault:"error"`
...@@ -31,7 +36,9 @@ type Config struct { ...@@ -31,7 +36,9 @@ type Config struct {
func New() ( *Config, error ){ func New() ( *Config, error ){
cfg := Config{} cfg := Config{
Version: version,
}
if err := configParser.Parse( &cfg ); err != nil { if err := configParser.Parse( &cfg ); err != nil {
return nil, err return nil, err
...@@ -61,7 +68,6 @@ func New() ( *Config, error ){ ...@@ -61,7 +68,6 @@ func New() ( *Config, error ){
) )
} }
if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 { if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 {
if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) { if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) {
return nil, errors.New( return nil, errors.New(
...@@ -81,6 +87,22 @@ func New() ( *Config, error ){ ...@@ -81,6 +87,22 @@ func New() ( *Config, error ){
} }
} }
if len( cfg.FontColor ) >= 1 {
if len( cfg.FontColor ) >= 21 {
return nil, errors.New(
fmt.Sprintln( "Font color too long" ),
)
}
for _, r := range cfg.FontColor {
if ! unicode.IsLetter( r ) {
return nil, errors.New(
fmt.Sprintln( "Invalid character in font color" ),
)
}
}
}
return &cfg, nil return &cfg, nil
} }
...@@ -48,7 +48,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, ...@@ -48,7 +48,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
data := indexHtmlData{ data := indexHtmlData{
Version: config.Version, Version: config.Version,
Color: "", Color: config.FontColor,
} }
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
...@@ -205,15 +205,15 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, ...@@ -205,15 +205,15 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
router.Get( "/states", func( c *f.Ctx ) error { router.Get( "/states", func( c *f.Ctx ) error {
states, err := store.Show() names, err := store.List()
if err != nil { if err != nil {
return c.SendStatus( http.StatusInternalServerError ) return c.SendStatus( http.StatusInternalServerError )
} }
const pathPrefix string = "/state" const pathPrefix string = "/state"
paths := make ( []string, len( states ) ) paths := make( []string, len( names ) )
for i, state := range states { for i, name := range names {
paths[ i ] = fmt.Sprintf( "%s/%s", pathPrefix, state ) paths[ i ] = fmt.Sprintf( "%s/%s", pathPrefix, name )
} }
headers := c.GetReqHeaders() headers := c.GetReqHeaders()
......
...@@ -64,15 +64,15 @@ func ( e *Ephemeral ) Fetch( name string ) ( *Item, error ) { ...@@ -64,15 +64,15 @@ func ( e *Ephemeral ) Fetch( name string ) ( *Item, error ) {
} }
func ( e *Ephemeral ) Show() ( []string, error ) { func ( e *Ephemeral ) List() ( []string, error ) {
if e.store == nil { if e.store == nil {
return nil, errors.New( "ephemeral storage not available" ) return nil, errors.New( "ephemeral storage not available" )
} }
e.mux.Lock() e.mux.Lock()
names := make( []string, 0, len( e.store ) ) names := make( []string, 0, len( e.store ) )
for k := range e.store { for _, item := range e.store {
names = append( names, k ) names = append( names, item.Name() )
} }
e.mux.Unlock() e.mux.Unlock()
......
package state
import (
"testing"
"mime"
"sync"
"github.com/stretchr/testify/assert"
)
var testItems = [] Item {
NewItem( "foo", "bar", []byte( "fasel" ) ),
NewItem( "qwertyASDFGH", mime.TypeByExtension( ".html" ), []byte{} ),
Item{
name: "Som!_🎵nam3",
mimeType: "any kind of string",
data: []byte{ 1, 2, 3, 4, 5, 6, 7, 8 },
},
}
func TestEphemeralAdd( t *testing.T ){
es := NewEphemeralStore()
wg := &sync.WaitGroup{}
for _, item := range testItems {
wg.Add( 1 )
go func( i Item ){
defer wg.Done()
es.Add( i )
}( item )
}
wg.Wait()
assert.Len( t, es.store, len( testItems ) )
}
...@@ -51,8 +51,8 @@ func ( e *Persistent ) Add( i Item ) error { ...@@ -51,8 +51,8 @@ func ( e *Persistent ) Add( i Item ) error {
name := i.Name() name := i.Name()
if err := e.client.HSet( if err := e.client.HSet(
ctx, name, ctx, name,
"data", i.Data(),
"mime", i.MimeType(), "mime", i.MimeType(),
"data", i.Data(),
).Err(); err != nil { ).Err(); err != nil {
return err return err
} }
...@@ -89,7 +89,7 @@ func ( e *Persistent ) Fetch( name string ) ( *Item, error ) { ...@@ -89,7 +89,7 @@ func ( e *Persistent ) Fetch( name string ) ( *Item, error ) {
} }
func ( e *Persistent ) Show() ( []string, error ) { func ( e *Persistent ) List() ( []string, error ) {
ctx, cancel := context.WithTimeout( context.TODO(), e.timeout ) ctx, cancel := context.WithTimeout( context.TODO(), e.timeout )
defer cancel() defer cancel()
......
...@@ -6,7 +6,7 @@ type Store interface { ...@@ -6,7 +6,7 @@ type Store interface {
Add( i Item ) error Add( i Item ) error
Remove( name string ) error Remove( name string ) error
Fetch( name string ) ( *Item, error ) Fetch( name string ) ( *Item, error )
Show() ( []string, error ) List() ( []string, error )
Disconnect() error Disconnect() error
} }