Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarespot committed Nov 20, 2024
0 parents commit e99eb4e
Show file tree
Hide file tree
Showing 38 changed files with 1,944 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go
on: [push, pull_request]

jobs:
test:
strategy:
matrix:
go-version: [1.23.x]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Test
run: go test -cover -v ./...
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: goreleaser

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
strategy:
matrix:
go-version: [1.23.x]

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: release --clean
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Taken from URL: https://github.com/github/gitignore/blob/main/Go.gitignore
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env

# Misc
bin/
56 changes: 56 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- id: porty
binary: porty
ldflags:
- -X github.com/softwarespot/porty/internal/version.Version={{.Version}}
- -X github.com/softwarespot/porty/internal/version.Time={{.Date}}
- -X github.com/softwarespot/porty/internal/version.User={{.Env.USER}}
- -X github.com/softwarespot/porty/internal/version.GoVersion={{.Env.GO_VERSION}}
- -s
- -w
env:
- CGO_ENABLED=0
- GO_VERSION=1.23
- USER=SoftwareSpot
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
goarm:
- '7'
ignore:
- goos: darwin
goarch: arm

archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
format: tar.xz
format_overrides:
- goos: windows
format: zip
wrap_in_directory: true
files:
- LICENSE
- README.md

checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'

release:
draft: false

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 SoftwareSpot Apps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# If the "VERSION" environment variable is not set, then use this value instead
VERSION?=1.0.0
TIME=$(shell date +%FT%T%z)
GOVERSION=$(shell go version | awk '{print $$3}' | sed s/go//)

LDFLAGS=-ldflags "\
-X github.com/softwarespot/porty/internal/version.Version=${VERSION} \
-X github.com/softwarespot/porty/internal/version.Time=${TIME} \
-X github.com/softwarespot/porty/internal/version.User=${USER} \
-X github.com/softwarespot/porty/internal/version.GoVersion=${GOVERSION} \
-s \
-w \
"

build:
@echo building to bin/porty
@go build $(LDFLAGS) -o ./bin/porty

install:
@echo copying bin/porty to $(HOME)/bin/porty
@mv ./bin/porty $(HOME)/bin/porty

test:
@go test -cover -v ./...

.PHONY: build install test
185 changes: 185 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Porty

![Go Tests](https://github.com/softwarespot/porty/actions/workflows/go.yml/badge.svg)

This application is a ports manager, for registering an application name and getting the next available port. The port range is 8000-9000.

## Prerequisites

- go 1.23.0 or above
- make (if you want to use the `Makefile` provided)

## Installation

`porty` is available on Linux, macOS and Windows platforms.
Binaries for Linux, Windows and Mac are available as tarballs in the [release page](https://github.com/softwarespot/porty/releases).

## Local

Build the binary `porty` executable to the directory `./bin` i.e. `./bin/porty`.

```bash
make
```

Install i.e. copy the executable `./bin/porty` to `$HOME/bin` (if it exists).

```bash
make install
```

Initialize the ports database.

```bash
porty init
```

### Get

Get or assign the next available port number for the app name.

```bash
# As text
porty get myapp

# As JSON
porty get myapp --json
```

### List

List all port numbers.

```bash
# As text
porty list

# As JSON
porty list --json
```

### Next

Get the next available port number, without assigning to an app name.

```bash
# As text
porty next

# As JSON
porty next --json
```

### Remove

Remove a port number for the app name.

```bash
# As text
porty remove myapp

# As JSON
porty remove myapp --json
```

### Who

Get who has been assigned to a port number.

```bash
# As text
porty who 8001

# As JSON
porty who 8001 --json
```

### Init

Initialize the ports database.

```bash
# As text
porty init

# As JSON
porty init --json
```

### Version

Display the version of the application.

```bash
# As text
porty version

# As JSON
porty version --text
```

### Help

Display the help text and exit.

```bash
porty --help
```

## Autocompletion

Adds autocompletion for the application's commands.

Add the following line to the `.bashrc` file; otherwise, refer to [kubectl's](https://kubernetes.io/docs/tasks/tools/install-kubectl/#optional-kubectl-configurations) documentation about locations for other OSs

- For `bash`

```bash
source <(porty completion bash)
```

- For `fish`

```bash
source <(porty completion fish)
```

- For `zsh`

```bash
source <(porty completion zsh)
```

### Example (bash)

Example of adding autocompletion for `bash` to the `.bashrc` file.

```bash
echo 'source <(porty completion bash)' >> ~/.bashrc
source ~/.bashrc
```

## Dependencies

**IMPORTANT:** 3rd party dependencies are used.

I only ever use dependencies when it's say an adapter for
an external service e.g. Redis, MySQL or Prometheus.

## Linting

Docker

```bash
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run -v --tests=false --disable-all -E durationcheck,errorlint,exhaustive,gocritic,gosimple,ineffassign,misspell,predeclared,revive,staticcheck,unparam,unused,whitespace --max-issues-per-linter=10000 --max-same-issues=10000
```

Local

```bash
golangci-lint run --tests=false --disable-all -E durationcheck,errorlint,exhaustive,gocritic,gosimple,ineffassign,misspell,predeclared,revive,staticcheck,unparam,unused,whitespace --max-issues-per-linter=10000 --max-same-issues=10000
```

## License

The code has been licensed under the [MIT](https://opensource.org/license/mit) license.
Loading

0 comments on commit e99eb4e

Please sign in to comment.