Skip to content

Commit d286cee

Browse files
awerisAli Akca
authored and
Ali Akca
committed
Initialize project structure
Signed-off-by: Ali Akca <[email protected]>
1 parent b00310e commit d286cee

19 files changed

+791
-2
lines changed

.bingo/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# Ignore everything
3+
*
4+
5+
# But not these files:
6+
!.gitignore
7+
!*.mod
8+
!README.md
9+
!Variables.mk
10+
!variables.env
11+
12+
*tmp.mod

.bingo/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Project Development Dependencies.
2+
3+
This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo.
4+
5+
* Run `bingo get` to install all tools having each own module file in this directory.
6+
* Run `bingo get <tool>` to install <tool> that have own module file in this directory.
7+
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod.
8+
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool
9+
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.
10+
11+
## Requirements
12+
13+
* Go 1.14+

.bingo/Variables.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.2. DO NOT EDIT.
2+
# All tools are designed to be build inside $GOBIN.
3+
GOPATH ?= $(shell go env GOPATH)
4+
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
5+
GO ?= $(shell which go)
6+
7+
# Bellow generated variables ensure that every time a tool under each variable is invoked, the correct version
8+
# will be used; reinstalling only if needed.
9+
# For example for golangci-lint variable:
10+
#
11+
# In your main Makefile (for non array binaries):
12+
#
13+
#include .bingo/Variables.mk # Assuming -dir was set to .bingo .
14+
#
15+
#command: $(GOLANGCI_LINT)
16+
# @echo "Running golangci-lint"
17+
# @$(GOLANGCI_LINT) <flags/args..>
18+
#
19+
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.32.0
20+
$(GOLANGCI_LINT): .bingo/golangci-lint.mod
21+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
22+
@echo "(re)installing $(GOBIN)/golangci-lint-v1.32.0"
23+
@cd .bingo && $(GO) build -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.32.0 "github.com/golangci/golangci-lint/cmd/golangci-lint"
24+

.bingo/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.

.bingo/golangci-lint.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.15
4+
5+
require github.com/golangci/golangci-lint v1.32.0 // cmd/golangci-lint

.bingo/variables.env

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.2. DO NOT EDIT.
2+
# All tools are designed to be build inside $GOBIN.
3+
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
4+
local gobin=$(go env GOBIN)
5+
6+
if [ -z "$gobin" ]; then
7+
gobin="$(go env GOPATH)/bin"
8+
fi
9+
10+
11+
GOLANGCI_LINT="${gobin}/golangci-lint-v1.32.0"
12+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Project Directories
2+
vendor/
3+
build/
4+
5+
# IDE
6+
.idea/
7+
.run/

.golangci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
run:
2+
# default concurrency is a available CPU number
3+
concurrency: 4
4+
# timeout for analysis, e.g. 30s, 5m, default is 1m
5+
deadline: 3m
6+
tests: true
7+
8+
linters:
9+
disable:
10+
- exhaustivestruct
11+
12+
linters-settings:
13+
lll:
14+
line-length: 160
15+
funlen:
16+
lines: 110
17+
statements: 60

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Project directories
2+
ROOT_DIR := $(CURDIR)
3+
4+
# Helper variables
5+
V = 0
6+
Q = $(if $(filter 1,$V),,@)
7+
M = $(shell printf "\033[34;1m▶\033[0m")
8+
9+
# External targets
10+
include .bingo/Variables.mk
11+
include scripts/make/help.mk
12+
include scripts/make/lint.mk
13+
include scripts/make/build.mk
14+
include scripts/make/test.mk

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
# postgres-data-dump
2-
Tool for dumping a sample of data from PostgreSQL
1+
# Postgres Data Dump
2+
3+
This is a simple tool for dumping a sample of data from a PostgreSQL database.
4+
The resulting dump can be loaded back into the new database using standard tools
5+
(e.g. `psql(1)`). The original project belongs to: [dankeder/pg_dump_sample](https://github.com/dankeder/pg_dump_sample)
6+
7+
## Why would I want this?
8+
9+
It is useful if you have a huge PostgreSQL database, and you need a
10+
database with a small dataset for testing or development.
11+
12+
## Usage
13+
14+
### CLI
15+
16+
```
17+
Usage of pdd:
18+
--log-format string log format to use. ('fmt', 'json') (default "fmt")
19+
--log-level string log filtering level. ('error', 'warn', 'info', 'debug') (default "error")
20+
-v, --verbose verbose output
21+
--version Prints version info
22+
```
23+
24+
## Development
25+
26+
```
27+
28+
Usage:
29+
make <target>
30+
31+
Targets:
32+
help shows this help message
33+
fix Fix found issues (if it's supported by the $(GOLANGCI_LINT))
34+
fmt Runs gofmt
35+
lint Runs golangci-lint analysis
36+
clean Cleanup everything
37+
vendor Updates vendored copy of dependencies
38+
build Builds binary
39+
version Shows application version
40+
test Runs go test
41+
```

cmd/main.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main
2+
3+
import (
4+
syslog "log"
5+
"os"
6+
7+
"github.com/aweris/postgres-data-dump/internal/log"
8+
"github.com/spf13/pflag"
9+
)
10+
11+
// Version represents the software version of the
12+
// nolint:gochecknoglobals
13+
var (
14+
version = "dev"
15+
commit = "none"
16+
date = "unknown"
17+
)
18+
19+
func main() {
20+
var (
21+
// logging
22+
logLevel string
23+
logFormat string
24+
verbose bool
25+
26+
// other
27+
showVersion bool
28+
)
29+
30+
flag := pflag.NewFlagSet("defaults", pflag.ExitOnError)
31+
32+
// no need to sort flags in help
33+
flag.SortFlags = false
34+
35+
// logging flags
36+
flag.StringVar(&logLevel, "log-level", log.LevelError, "log filtering level. ('error', 'warn', 'info', 'debug')")
37+
flag.StringVar(&logFormat, "log-format", log.FormatFmt, "log format to use. ('fmt', 'json')")
38+
flag.BoolVarP(&verbose, "verbose", "v", false, "verbose output")
39+
40+
// other flags
41+
flag.BoolVar(&showVersion, "version", false, "Prints version info")
42+
43+
// bind environment variables
44+
bindEnv(flag.Lookup("log-level"), "PDD_LOG_LEVEL")
45+
bindEnv(flag.Lookup("log-format"), "PDD_LOG_FORMAT")
46+
47+
// Parse Options
48+
if err := flag.Parse(os.Args); err != nil {
49+
syslog.Fatalf("%#v", err)
50+
}
51+
52+
// print application version
53+
if showVersion {
54+
syslog.Printf("Version : %s\n", version)
55+
syslog.Printf("Git Commit : %s\n", commit)
56+
syslog.Printf("Build Date : %s\n", date)
57+
os.Exit(0)
58+
}
59+
60+
// Enable log level debug for verbose
61+
if verbose {
62+
logLevel = log.LevelDebug
63+
}
64+
65+
logger, err := log.NewLogger(logLevel, logFormat, "pdd")
66+
if err != nil {
67+
syslog.Fatalf("%#v", err)
68+
}
69+
70+
logger.Debug("version", version, "git commit", commit, "build date", date)
71+
}
72+
73+
func bindEnv(fn *pflag.Flag, env string) {
74+
if fn == nil || fn.Changed {
75+
return
76+
}
77+
78+
val := os.Getenv(env)
79+
80+
if len(val) > 0 {
81+
if err := fn.Value.Set(val); err != nil {
82+
syslog.Fatalf("failed to bind env: %v\n", err)
83+
}
84+
}
85+
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/aweris/postgres-data-dump
2+
3+
go 1.15
4+
5+
require (
6+
github.com/go-kit/kit v0.10.0
7+
github.com/spf13/pflag v1.0.5
8+
)

0 commit comments

Comments
 (0)