Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches: [master, refresh]
pull_request:
branches: [master]

jobs:
test:
name: Test (Go ${{ matrix.go-version }})
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22', '1.23']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Download dependencies
run: go mod download

- name: Run vet
run: go vet ./...

- name: Run tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.txt
fail_ci_if_error: false

build:
name: Build
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Build pilad
run: go build -v ./pilad

- name: Build main
run: go build -v .
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

27 changes: 0 additions & 27 deletions Gopkg.lock

This file was deleted.

37 changes: 0 additions & 37 deletions Gopkg.toml

This file was deleted.

32 changes: 13 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
.PHONY: vet lint
.PHONY: default all test testv race vet build clean

default: vet get test
default: vet test

all: vet lint get test

get:
go get ./...
all: vet test build

test:
go list ./... | grep -v /vendor/ | xargs -L1 go test -cover
go test -cover ./...

testv:
go list ./... | grep -v /vendor/ | xargs -L1 go test -v -cover
go test -v -cover ./...

race:
go list ./... | grep -v /vendor/ | xargs -L1 go test -race
go test -race ./...

vet:
go list ./... | grep -v /vendor/ | xargs -L1 go vet

lint:
go list ./... | grep -v /vendor/ | xargs -L1 golint
go vet ./...

pilad: get
$(GOPATH)/bin/pilad
build:
go build -o bin/pilad ./pilad

gox: get
gox -osarch="linux/amd64 darwin/amd64" -output "dist/{{.OS}}/{{.Arch}}/$(git rev-parse HEAD)/{{.Dir}}" ./pilad
clean:
rm -rf bin/ coverage.txt

release:
docker run --rm --name="piladb_release" -v "$(PWD)":/gopath/src/github.com/fern4lvarez/piladb -w /gopath/src/github.com/fern4lvarez/piladb tcnksm/gox:latest make gox
coverage:
go test -coverprofile=coverage.txt -covermode=atomic ./...
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
piladb [![Build Status](https://travis-ci.org/fern4lvarez/piladb.svg?branch=master)](https://travis-ci.org/fern4lvarez/piladb) [![GoDoc](https://godoc.org/github.com/fern4lvarez/piladb?status.svg)](https://godoc.org/github.com/fern4lvarez/piladb) [![Go Report Card](https://goreportcard.com/badge/github.com/fern4lvarez/piladb)](https://goreportcard.com/report/github.com/fern4lvarez/piladb) [![codecov](https://codecov.io/gh/fern4lvarez/piladb/branch/master/graph/badge.svg)](https://codecov.io/gh/fern4lvarez/piladb) [![osw](https://img.shields.io/badge/%E2%89%85osw-supported-blue.svg)](http://oscillating.works)
piladb [![Go Reference](https://pkg.go.dev/badge/github.com/fern4lvarez/piladb.svg)](https://pkg.go.dev/github.com/fern4lvarez/piladb) [![Go Report Card](https://goreportcard.com/badge/github.com/fern4lvarez/piladb)](https://goreportcard.com/report/github.com/fern4lvarez/piladb)
======

![Logo](http://i.imgur.com/tjQbm56.png)
Expand All @@ -21,13 +21,15 @@ Features
* Manage elements in JSON-compatible data types: strings, numbers, arrays, objects, etc.
* Totally configurable using a REST API, or CLI parameters.
* In-memory store.
* Graceful shutdown support.
* Structured logging using Go's `log/slog` package.
* Written in Go, i.e. binaries are self-contained and distributable.

Documentation
-------------

* [Main documentation page](http://docs.piladb.org).
* [Go `pila` package documentation](https://godoc.org/github.com/fern4lvarez/piladb/pila).
* [Go `pila` package documentation](https://pkg.go.dev/github.com/fern4lvarez/piladb/pila).
* [`pilad`'s RESTful API documentation](pilad/).

Install
Expand All @@ -39,11 +41,11 @@ page.

### From Source Code

> You need Go installed. Version 1.6+ recommended.
> You need Go 1.21 or later installed.

```bash
go get github.com/fern4lvarez/piladb/...
cd $GOPATH/src/github.com/fern4lvarez/piladb
git clone https://github.com/fern4lvarez/piladb.git
cd piladb
make pilad
```

Expand All @@ -60,11 +62,11 @@ Clients
Development
-----------

> You need Go installed. Version 1.6+ is mandatory.
> You need Go 1.21 or later installed.

```bash
go get github.com/fern4lvarez/piladb/...
cd $GOPATH/src/github.com/fern4lvarez/piladb
git clone https://github.com/fern4lvarez/piladb.git
cd piladb
make all
```

Expand All @@ -77,12 +79,11 @@ Dependencies
**piladb** aims to minimize the amount of third party dependencies and to rely on
the Go standard library as much as possible.

Even though, it uses [`dep`](https://golang.github.io/dep/) to vendor its few
dependencies.
**piladb** uses [Go modules](https://go.dev/doc/modules/managing-dependencies) for dependency management.

**piladb** also provides a `go.mod` file, which turns this project into a Go module.
To learn more about Go modules and the `vgo` prototype, please read the
[Go & Versioning](https://research.swtch.com/vgo) series by Russ Cox.
Current dependencies:
* [`gorilla/mux`](https://github.com/gorilla/mux) - HTTP router
* [`mitchellh/go-homedir`](https://github.com/mitchellh/go-homedir) - Home directory detection

Code Coverage
-------------
Expand Down
12 changes: 2 additions & 10 deletions dev/tests.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#!/usr/bin/env bash

# This script runs all project tests
# putting all coverage reports in a same
# file.
# with coverage reports.

set -e
echo "" > coverage.txt

for d in $(go list ./... | grep -v vendor); do
go test -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
go test -coverprofile=coverage.txt -covermode=atomic ./...
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module "github.com/fern4lvarez/piladb"
module github.com/fern4lvarez/piladb

go 1.21

require (
"github.com/gorilla/context" v0.0.0-20160226214623-1ea25387ff6f
"github.com/gorilla/mux" v1.6.1
"github.com/mitchellh/go-homedir" v0.0.0-20161203194507-b8bc1bf76747
github.com/gorilla/mux v1.8.1
github.com/mitchellh/go-homedir v1.1.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
25 changes: 13 additions & 12 deletions pilad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"log"
"log/slog"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -67,15 +67,15 @@ type stackHandlerFunc func(w http.ResponseWriter, r *http.Request, stack *pila.S
func (c *Conn) configHandler(w http.ResponseWriter, r *http.Request) {
res, err := c.Config.Values.StacksKV().ToJSON()
if err != nil {
log.Println(r.Method, r.URL, http.StatusBadRequest,
"error on response serialization:", err)
slog.Warn("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusBadRequest,
"error", "response serialization failed", "details", err)
w.WriteHeader(http.StatusBadRequest)
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(res)
log.Println(r.Method, r.URL, http.StatusOK)
slog.Info("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusOK)
}

// configKeyHandler handles a config value.
Expand Down Expand Up @@ -103,29 +103,29 @@ func (c *Conn) configKeyHandler(configKey string) http.Handler {
}
if r.Method == "POST" {
if r.Body == nil {
log.Println(r.Method, r.URL, http.StatusBadRequest,
"no element provided")
slog.Warn("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusBadRequest,
"error", "no element provided")
w.WriteHeader(http.StatusBadRequest)
return
}
err := element.Decode(r.Body)
if err != nil {
log.Println(r.Method, r.URL, http.StatusBadRequest,
"error on decoding element:", err)
slog.Warn("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusBadRequest,
"error", "element decode failed", "details", err)
w.WriteHeader(http.StatusBadRequest)
return
}

c.Config.Set(vars["key"], element.Value)
}

log.Println(r.Method, r.URL, http.StatusOK, element.Value)
slog.Info("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusOK, "value", element.Value)
w.Header().Set("Content-Type", "application/json")

b, err := element.ToJSON()
if err != nil {
log.Println(r.Method, r.URL, http.StatusBadRequest,
"error on decoding element:", err)
slog.Warn("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusBadRequest,
"error", "element encode failed", "details", err)
w.WriteHeader(http.StatusBadRequest)
return
}
Expand All @@ -138,7 +138,8 @@ func (c *Conn) configKeyHandler(configKey string) http.Handler {
func (c *Conn) checkMaxStackSize(handler stackHandlerFunc) stackHandlerFunc {
return func(w http.ResponseWriter, r *http.Request, stack *pila.Stack) {
if s := c.Config.MaxStackSize(); stack.Size() >= s && s != -1 {
log.Println(r.Method, r.URL, http.StatusNotAcceptable, vars.MaxStackSize, "value reached")
slog.Warn("request", "method", r.Method, "url", r.URL.String(), "status", http.StatusNotAcceptable,
"error", "max_stack_size reached", "max_stack_size", vars.MaxStackSize)
w.WriteHeader(http.StatusNotAcceptable)
return
}
Expand Down
Loading
Loading