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
  • gjahn/webservice-ws-2425
  • s75359/webservice
  • ouch4861/webservice-ws-24-oc
  • s92274/webservice-msws-24
  • ewbo4360/webservice
20 results
Show changes
Commits on Source (4)
......@@ -37,6 +37,7 @@ $(BIN_DIR)/artifact.bin:
cd $(SRC_DIR) \
&& go build \
-o $(@) \
-ldflags "-X webservice/configuration.version=0.0.1" \
$(SRC_DIR)/*.go
.PHONY: build-linux
......
......@@ -24,9 +24,11 @@ information checkout the [configuration code](./configuration/config.go).
3. Execute unit tests: `go test -race -v ./...`
4. Build artifact: `go build -o ./artifact.bin ./*.go`
To build for another platform, set `GOOS` and `GOARCH`. To yield a static binary (fully
self-contained, no dynamic linking) set `CGO_ENABLED=0`. For more details, please refer
to the [Makefile](./Makefile).
To build for another platform, set `GOOS` and `GOARCH`. To yield a static
binary (fully self-contained, no dynamic linking) set `CGO_ENABLED=0`.
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:
......
......@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"unicode"
fp "path/filepath"
configParser "github.com/caarlos0/env/v9"
......@@ -12,9 +13,13 @@ import (
const BODY_SIZE_LIMIT = 32 * 1024 * 1024 // 32 MB, in bytes
var version string = "n/a"
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"`
......@@ -31,7 +36,9 @@ type Config struct {
func New() ( *Config, error ){
cfg := Config{}
cfg := Config{
Version: version,
}
if err := configParser.Parse( &cfg ); err != nil {
return nil, err
......@@ -61,7 +68,6 @@ func New() ( *Config, error ){
)
}
if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 {
if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) {
return nil, errors.New(
......@@ -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
}
......@@ -48,7 +48,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
data := indexHtmlData{
Version: config.Version,
Color: "",
Color: config.FontColor,
}
buffer := &bytes.Buffer{}
......@@ -205,15 +205,15 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
router.Get( "/states", func( c *f.Ctx ) error {
states, err := store.Show()
names, err := store.List()
if err != nil {
return c.SendStatus( http.StatusInternalServerError )
}
const pathPrefix string = "/state"
paths := make ( []string, len( states ) )
for i, state := range states {
paths[ i ] = fmt.Sprintf( "%s/%s", pathPrefix, state )
paths := make( []string, len( names ) )
for i, name := range names {
paths[ i ] = fmt.Sprintf( "%s/%s", pathPrefix, name )
}
headers := c.GetReqHeaders()
......
......@@ -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 {
return nil, errors.New( "ephemeral storage not available" )
}
e.mux.Lock()
names := make( []string, 0, len( e.store ) )
for k := range e.store {
names = append( names, k )
for _, item := range e.store {
names = append( names, item.Name() )
}
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 {
name := i.Name()
if err := e.client.HSet(
ctx, name,
"data", i.Data(),
"mime", i.MimeType(),
"data", i.Data(),
).Err(); err != nil {
return err
}
......@@ -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 )
defer cancel()
......
......@@ -6,7 +6,7 @@ type Store interface {
Add( i Item ) error
Remove( name string ) error
Fetch( name string ) ( *Item, error )
Show() ( []string, error )
List() ( []string, error )
Disconnect() error
}