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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
76 changes: 76 additions & 0 deletions .github/workflows/ow-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Build Container Image for ow-exporter

on:
push:
paths:
- "build/ow-exporter/**"
- "cmd/ow-exporter/**"
- "go.mod"
- "go.sum"
- ".github/workflows/ow-exporter.yaml"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5.8.0
with:
images: ghcr.io/lexfrei/ow-exporter
flavor: |
latest=true
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha

- name: Set up QEMU
uses: docker/setup-qemu-action@v3.6.0
with:
platforms: "arm64,amd64"

- name: Checkout
uses: actions/checkout@v5.0.0

- name: Set up Docker Context for Buildx
id: buildx-context
run: |
docker context create builders

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3.11.1
with:
endpoint: builders
config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]

- name: Login to GitHub Container Registry
uses: docker/login-action@v3.5.0
if: github.ref == 'refs/heads/master'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build and push
uses: docker/build-push-action@v6.18.0
if: github.ref == 'refs/heads/master'
with:
push: true
context: .
file: ./build/ow-exporter/Containerfile
platforms: linux/arm64, linux/amd64
tags: ${{ steps.docker_meta.outputs.tags }}

- name: Build
uses: docker/build-push-action@v6.18.0
if: github.ref == !'refs/heads/master'
with:
context: .
file: ./build/ow-exporter/Containerfile
platforms: linux/arm64, linux/amd64
tags: ${{ steps.docker_meta.outputs.tags }}
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ $RECYCLE.BIN/
# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,windows,macos

deployments/vk2tg/compose/local.env

# Project-specific binaries
/ow-exporter
cmd/ow-exporter/ow-exporter

# OverFast API source code for reference
overfast-api/

# Node.js (not needed for Go project)
node_modules/
package.json
package-lock.json

# Temporary debug/development files
*.html
debug_profile.html

# Configuration files with personal data
config/players.yaml
cmd/ow-exporter/config/
*/config/players.yaml
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ linters:
- gochecknoglobals
- gochecknoinits
- nonamedreturns
- wsl
- wsl_v5
settings:
dupl:
threshold: 100
Expand Down
163 changes: 163 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,169 @@ The project follows standard Go conventions with strict linting rules. Pay atten
- Import formatting with goimports and gofumpt
- Error handling patterns using `github.com/cockroachdb/errors`

## Go Code Style Guide

Based on golangci-lint configuration and current linting errors, follow these specific style guidelines:

### Standard Libraries (from ~/PROMPT.md)
- **Logging**: `slog` (standard library)
- **Errors**: `github.com/cockroachdb/errors`
- **Web framework**: `github.com/labstack/echo/v4`
- **CLI**: `github.com/spf13/cobra`
- **Configuration**: `github.com/spf13/viper`

### Function and Method Guidelines
- **Function length**: Maximum 60 lines (funlen)
- **Cognitive complexity**: Maximum 30 (gocognit)
- **Cyclomatic complexity**: Maximum 10 (gocyclo)
- Break down complex functions into smaller, focused functions
- Use helper methods to reduce complexity

### Line Length and Formatting
- **Maximum line length**: 120 characters (lll)
- For struct tags that exceed line length:
```go
// Good - break long struct tags across lines
type HeroStats struct {
TimePlayed time.Duration `ow:"time_played"
prometheus:"ow_hero_time_played_seconds"
help:"Total time played on hero"
path:"[data-category-id='0x0860000000000021']"
type:"duration"`
}
```

### Constants and Magic Numbers
- **Extract repeated strings** as constants (goconst):
```go
// Good
const MouseKeyboardViewActiveSelector = ".mouseKeyboard-view.is-active"
const QuickPlayViewActiveSelector = ".quickPlay-view.is-active"
```
- **Avoid magic numbers** (mnd) - define as constants with meaningful names:
```go
// Bad
time.Sleep(30 * time.Second)

// Good
const DefaultTimeout = 30 * time.Second
time.Sleep(DefaultTimeout)
```

### Variable Naming
- **Minimum 3 characters** for variable names (varnamelen)
- Use descriptive names:
```go
// Bad
e := echo.New()
s := "hello"

// Good
server := echo.New()
message := "hello"
```

### Documentation Standards
- **All comments must end with periods** (godot):
```go
// Good comment ends with a period.
func doSomething() {}
```
- **Document all exported functions and types** (godoclint)
- Use proper Go doc comment format

### Struct Tags and JSON Naming
- **Use camelCase for JSON tags** (tagliatelle):
```go
// Good
type Player struct {
BattleTag string `json:"battleTag" yaml:"battletag"`
LastResolved *time.Time `json:"lastResolved" yaml:"lastResolved"`
}
```
- **Align struct tags** (tagalign) for better readability:
```go
type Config struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Database string `json:"database" yaml:"database"`
}
```

### Context Handling
- **Pass context as first parameter** (noctx) in functions that might need it:
```go
// Good
func fetchData(ctx context.Context, url string) error {
// implementation
}
```

### Loop Patterns
- **Use integer ranges for Go 1.22+** (intrange):
```go
// Modern Go 1.22+ style
for i := range 10 {
// process i
}

// Instead of
for i := 0; i < 10; i++ {
// process i
}
```

### Line Spacing (nlreturn)
- **Add blank lines before return statements** when they follow blocks:
```go
// Good
if condition {
doSomething()
}

return result
```

### Testing Standards
- **Use parallel tests** where appropriate (paralleltest):
```go
func TestSomething(t *testing.T) {
t.Parallel() // Add this for independent tests

// test implementation
}
```

### TODOs and Technical Debt
- **Minimize TODO comments** (godox)
- When TODOs are necessary, make them specific and actionable
- Include issue references or deadlines where possible

### Prometheus Metrics
- **Follow Prometheus naming conventions** (promlinter):
```go
// Good metric names
"http_requests_total" // counter
"request_duration_seconds" // histogram
"current_connections" // gauge
```

### Error Handling Patterns
- Use sentinel errors for expected conditions
- Wrap errors with context using `github.com/cockroachdb/errors`
- Don't return `nil, nil` - use meaningful errors instead

### Code Organization
- Keep related functionality together
- Use meaningful package names
- Prefer composition over inheritance
- Use interfaces for dependencies

### File Permissions and Security
- Use octal notation for file permissions: `0o600` not `0600`
- Never commit secrets or credentials
- Use environment variables for sensitive configuration

### Adding New Tools
When adding a new CLI tool:
1. Create directory under `cmd/<tool-name>/`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This monorepo contains various Go-based CLI tools and containerized services for
|------|-------------|-----------|--------|
| **[me-site](cmd/me-site/)** | Personal website with static content | `ghcr.io/lexfrei/me-site` | βœ… Active |
| **[a200](build/a200/)** | Simple nginx server that responds 200 to all requests | `ghcr.io/lexfrei/a200` | βœ… Active |
| **[ow-exporter](cmd/ow-exporter/)** | Overwatch 2 statistics exporter for Prometheus | `ghcr.io/lexfrei/ow-exporter` | 🚧 Development |
| **[redis-ui](cmd/redis-ui/)** | Web UI for Redis database management | - | πŸ”§ Development |

### Social & Communication
Expand Down
2 changes: 1 addition & 1 deletion build/ow-exporter/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN echo 'nobody:x:65534:65534:Nobody:/:' > /tmp/passwd && \
WORKDIR /go/src/github.com/lexfrei/tools/
COPY . /go/src/github.com/lexfrei/tools/

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o ow-exporter ./cmd/ow-exporter/ow-exporter.go && \
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o ow-exporter ./cmd/ow-exporter && \
upx --best --lzma ow-exporter

FROM scratch
Expand Down
Loading