Skip to content

Commit

Permalink
cleaning up src ^^
Browse files Browse the repository at this point in the history
- rm `vendor` folder
- bump ext dep.
- github actions
- ...
  • Loading branch information
wakeful committed Oct 12, 2022
1 parent 253bb4e commit ace19ee
Show file tree
Hide file tree
Showing 37 changed files with 288 additions and 10,058 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version: '>=1.19.2'
cache: true
- uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea/
out/
release/
dist/
11 changes: 11 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters:
enable-all: true
disable:
- forbidigo
- funlen
- lll
- gochecknoglobals
- paralleltest
- scopelint
- testpackage
- varnamelen
23 changes: 23 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# todo add to CI
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2017, AJ
Copyright (c) 2022, AJ
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@

A small tool for converting YAML files into JSON.

## Installation

macOS
```
$ brew tap wakeful/selection
$ brew install yaml2json
```

Linux
```
curl -Lo yaml2json https://github.com/wakeful/yaml2json/releases/latest/download/yaml2json-linux-amd64 && chmod +x yaml2json && sudo mv yaml2json /usr/local/bin/
```

src
```
go get -u github.com/wakeful/yaml2json
```

## Usage

stdin pipe:

```
cat file.yml | yaml2json
```

or specify a file:

```
yaml2json path/file.yml
```
33 changes: 0 additions & 33 deletions decode.go

This file was deleted.

9 changes: 2 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module github.com/wakeful/yaml2json

go 1.12
go 1.19

require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/kr/pretty v0.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
require gopkg.in/yaml.v2 v2.4.0
14 changes: 3 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
20 changes: 0 additions & 20 deletions help.go

This file was deleted.

25 changes: 0 additions & 25 deletions input.go

This file was deleted.

41 changes: 41 additions & 0 deletions pkg/parse/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package parse

import (
"encoding/json"
"fmt"

"gopkg.in/yaml.v2"
)

func decode(input interface{}) interface{} {
switch element := input.(type) {
case map[interface{}]interface{}:
rec := map[string]interface{}{}

for key, value := range element {
rec[fmt.Sprintf("%v", key)] = decode(value)
}

return rec
case []interface{}:
for key, value := range element {
element[key] = decode(value)
}
}

return input
}

func ByteSliceToJSON(input []byte) (string, error) {
var unYaml interface{}
if err := yaml.Unmarshal(input, &unYaml); err != nil {
return "", fmt.Errorf("%w", err)
}

output, err := json.Marshal(decode(unYaml))
if err != nil {
return "", fmt.Errorf("%w", err)
}

return string(output), nil
}
Loading

0 comments on commit ace19ee

Please sign in to comment.