├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug.yml │ ├── config.yml │ ├── question.yml │ └── suggestion.yml ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml ├── images │ ├── card.svg │ ├── flat_blue.svg │ ├── flat_brightgreen.svg │ ├── flat_critical.svg │ ├── flat_custom.svg │ ├── flat_green.svg │ ├── flat_important.svg │ ├── flat_inactive.svg │ ├── flat_informational.svg │ ├── flat_japanese.svg │ ├── flat_lightgrey.svg │ ├── flat_orange.svg │ ├── flat_red.svg │ ├── flat_simple_blue.svg │ ├── flat_simple_brightgreen.svg │ ├── flat_simple_critical.svg │ ├── flat_simple_custom.svg │ ├── flat_simple_green.svg │ ├── flat_simple_important.svg │ ├── flat_simple_inactive.svg │ ├── flat_simple_informational.svg │ ├── flat_simple_japanese.svg │ ├── flat_simple_lightgrey.svg │ ├── flat_simple_orange.svg │ ├── flat_simple_red.svg │ ├── flat_simple_success.svg │ ├── flat_simple_yellow.svg │ ├── flat_simple_yellowgreen.svg │ ├── flat_success.svg │ ├── flat_yellow.svg │ ├── flat_yellowgreen.svg │ ├── godoc.svg │ ├── license.svg │ ├── plastic_blue.svg │ ├── plastic_brightgreen.svg │ ├── plastic_critical.svg │ ├── plastic_custom.svg │ ├── plastic_green.svg │ ├── plastic_important.svg │ ├── plastic_inactive.svg │ ├── plastic_informational.svg │ ├── plastic_japanese.svg │ ├── plastic_lightgrey.svg │ ├── plastic_orange.svg │ ├── plastic_red.svg │ ├── plastic_simple_blue.svg │ ├── plastic_simple_brightgreen.svg │ ├── plastic_simple_critical.svg │ ├── plastic_simple_custom.svg │ ├── plastic_simple_green.svg │ ├── plastic_simple_important.svg │ ├── plastic_simple_inactive.svg │ ├── plastic_simple_informational.svg │ ├── plastic_simple_japanese.svg │ ├── plastic_simple_lightgrey.svg │ ├── plastic_simple_orange.svg │ ├── plastic_simple_red.svg │ ├── plastic_simple_success.svg │ ├── plastic_simple_yellow.svg │ ├── plastic_simple_yellowgreen.svg │ ├── plastic_success.svg │ ├── plastic_yellow.svg │ ├── plastic_yellowgreen.svg │ ├── square_blue.svg │ ├── square_brightgreen.svg │ ├── square_critical.svg │ ├── square_custom.svg │ ├── square_green.svg │ ├── square_important.svg │ ├── square_inactive.svg │ ├── square_informational.svg │ ├── square_japanese.svg │ ├── square_lightgrey.svg │ ├── square_orange.svg │ ├── square_red.svg │ ├── square_simple_blue.svg │ ├── square_simple_brightgreen.svg │ ├── square_simple_critical.svg │ ├── square_simple_custom.svg │ ├── square_simple_green.svg │ ├── square_simple_important.svg │ ├── square_simple_inactive.svg │ ├── square_simple_informational.svg │ ├── square_simple_japanese.svg │ ├── square_simple_lightgrey.svg │ ├── square_simple_orange.svg │ ├── square_simple_red.svg │ ├── square_simple_success.svg │ ├── square_simple_yellow.svg │ ├── square_simple_yellowgreen.svg │ ├── square_success.svg │ ├── square_yellow.svg │ └── square_yellowgreen.svg └── workflows │ ├── ci.yml │ ├── codeql.yml │ └── godoc.yml ├── .gitignore ├── .typos.toml ├── LICENSE ├── Makefile ├── README.md ├── SECURITY.md ├── badge.go ├── badge_test.go ├── go.mod ├── go.sum └── testdata ├── black.svg ├── flat.svg ├── flat_simple.svg ├── plastic.svg ├── plastic_simple.svg ├── square.svg ├── square_simple.svg └── white.svg /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This Code of Conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at `conduct@essentialkaos.com`. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | **IMPORTANT! Contribute your code only if you have an excellent understanding of project idea and all existing code base. Otherwise, a nicely formatted issue will be more helpful to us.** 4 | 5 | ### Issues 6 | 7 | 1. Provide product version where the problem was found; 8 | 2. Provide info about your environment; 9 | 3. Provide detailed info about your problem; 10 | 4. Provide steps to reproduce the problem; 11 | 5. Provide actual and expected results. 12 | 13 | ### Code 14 | 15 | 1. Check your code **before** creating pull request; 16 | 2. If tests are present in a project, add tests for your code; 17 | 3. Add inline documentation for your code; 18 | 4. Apply code style used throughout the project; 19 | 5. Create your pull request to `develop` branch (_pull requests to other branches are not allowed_). 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: ❗ Bug Report 2 | description: File a bug report 3 | title: "[Bug]: " 4 | labels: ["issue • bug"] 5 | assignees: 6 | - andyone 7 | 8 | body: 9 | - type: markdown 10 | attributes: 11 | value: | 12 | > [!IMPORTANT] 13 | > Before you open an issue, search GitHub Issues for a similar bug reports. If so, please add a 👍 reaction to the existing issue. 14 | 15 | - type: textarea 16 | attributes: 17 | label: Module version info 18 | description: Output of `grep 'github.com/essentialkaos/go-badge' go.sum` command 19 | render: shell 20 | validations: 21 | required: true 22 | 23 | - type: textarea 24 | attributes: 25 | label: Steps to reproduce 26 | description: Short guide on how to reproduce this problem on our site 27 | placeholder: | 28 | 1. [First Step] 29 | 2. [Second Step] 30 | 3. [and so on...] 31 | validations: 32 | required: true 33 | 34 | - type: textarea 35 | attributes: 36 | label: Expected behavior 37 | description: What you expected to happen 38 | validations: 39 | required: true 40 | 41 | - type: textarea 42 | attributes: 43 | label: Actual behavior 44 | description: What actually happened 45 | validations: 46 | required: true 47 | 48 | - type: textarea 49 | attributes: 50 | label: Additional info 51 | description: Include gist of relevant config, logs, etc. 52 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | 3 | contact_links: 4 | - name: Security Policies and Procedures 5 | url: https://github.com/essentialkaos/.github/blob/master/SECURITY.md 6 | about: Security procedures and general policies for all ESSENTIAL KAOS projects. 7 | 8 | - name: Contributing Guidelines 9 | url: https://github.com/essentialkaos/contributing-guidelines/blob/master/CONTRIBUTING.md 10 | about: Contributing Guidelines for all ESSENTIAL KAOS projects 11 | 12 | - name: Go Version Support Policy 13 | url: https://github.com/essentialkaos/.github/blob/master/GO-VERSION-SUPPORT.md 14 | about: Information about supported Go versions 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: ❓ Question 2 | description: Question about application, configuration or code 3 | title: "[Question]: " 4 | labels: ["issue • question"] 5 | assignees: 6 | - andyone 7 | 8 | body: 9 | - type: markdown 10 | attributes: 11 | value: | 12 | > [!IMPORTANT] 13 | > Before you open an issue, search GitHub Issues for a similar question. If so, please add a 👍 reaction to the existing issue. 14 | 15 | - type: textarea 16 | attributes: 17 | label: Question 18 | description: Detailed question 19 | validations: 20 | required: true 21 | 22 | - type: textarea 23 | attributes: 24 | label: Module version info 25 | description: Output of `grep 'github.com/essentialkaos/go-badge' go.sum` command 26 | render: shell 27 | validations: 28 | required: true 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggestion.yml: -------------------------------------------------------------------------------- 1 | name: ➕ Suggestion 2 | description: Suggest new feature or improvement 3 | title: "[Suggestion]: " 4 | labels: ["issue • suggestion"] 5 | assignees: 6 | - andyone 7 | 8 | body: 9 | - type: markdown 10 | attributes: 11 | value: | 12 | > [!IMPORTANT] 13 | > Before you open an issue, search GitHub Issues for a similar feature requests. If so, please add a 👍 reaction to the existing issue. 14 | > 15 | > Opening a feature request kicks off a discussion. Requests may be closed if we're not actively planning to work on them. 16 | 17 | - type: textarea 18 | attributes: 19 | label: Proposal 20 | description: Description of the feature 21 | validations: 22 | required: true 23 | 24 | - type: textarea 25 | attributes: 26 | label: Current behavior 27 | description: What currently happens 28 | validations: 29 | required: true 30 | 31 | - type: textarea 32 | attributes: 33 | label: Desired behavior 34 | description: What you would like to happen 35 | validations: 36 | required: true 37 | 38 | - type: textarea 39 | attributes: 40 | label: Use case 41 | description: Why is this important (helps with prioritizing requests) 42 | validations: 43 | required: true 44 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### What did you implement: 2 | 3 | Closes #XXXXX 4 | 5 | ### How did you implement it: 6 | 7 | ... 8 | 9 | ### How can we verify it: 10 | 11 | ... 12 | 13 | ### TODO's: 14 | 15 | - [ ] Write tests 16 | - [ ] Write documentation 17 | - [ ] Check that there aren't other open pull requests for the same issue/feature 18 | - [ ] Format your source code by `make fmt` 19 | - [ ] Provide verification config / commands 20 | - [ ] Enable "Allow edits from maintainers" for this PR 21 | - [ ] Update the messages below 22 | 23 | **Is this ready for review?:** No 24 | **Is it a breaking change?:** No 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: "gomod" 5 | directory: "/" 6 | target-branch: "develop" 7 | schedule: 8 | interval: "daily" 9 | timezone: "Etc/UTC" 10 | time: "03:00" 11 | labels: 12 | - "PR • MAINTENANCE" 13 | assignees: 14 | - "andyone" 15 | reviewers: 16 | - "andyone" 17 | groups: 18 | all: 19 | applies-to: version-updates 20 | update-types: 21 | - "minor" 22 | - "patch" 23 | 24 | - package-ecosystem: "github-actions" 25 | directory: "/" 26 | target-branch: "develop" 27 | schedule: 28 | interval: "daily" 29 | timezone: "Etc/UTC" 30 | time: "03:00" 31 | labels: 32 | - "PR • MAINTENANCE" 33 | assignees: 34 | - "andyone" 35 | reviewers: 36 | - "andyone" 37 | -------------------------------------------------------------------------------- /.github/images/card.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/images/flat_blue.svg: -------------------------------------------------------------------------------- 1 | flat: blueflatblue -------------------------------------------------------------------------------- /.github/images/flat_brightgreen.svg: -------------------------------------------------------------------------------- 1 | flat: brightgreenflatbrightgreen -------------------------------------------------------------------------------- /.github/images/flat_critical.svg: -------------------------------------------------------------------------------- 1 | flat: criticalflatcritical -------------------------------------------------------------------------------- /.github/images/flat_custom.svg: -------------------------------------------------------------------------------- 1 | flat: #ff69b4flat#ff69b4 -------------------------------------------------------------------------------- /.github/images/flat_green.svg: -------------------------------------------------------------------------------- 1 | flat: greenflatgreen -------------------------------------------------------------------------------- /.github/images/flat_important.svg: -------------------------------------------------------------------------------- 1 | flat: importantflatimportant -------------------------------------------------------------------------------- /.github/images/flat_inactive.svg: -------------------------------------------------------------------------------- 1 | flat: inactiveflatinactive -------------------------------------------------------------------------------- /.github/images/flat_informational.svg: -------------------------------------------------------------------------------- 1 | flat: informationalflatinformational -------------------------------------------------------------------------------- /.github/images/flat_japanese.svg: -------------------------------------------------------------------------------- 1 | ラベル: メッセージラベルメッセージ -------------------------------------------------------------------------------- /.github/images/flat_lightgrey.svg: -------------------------------------------------------------------------------- 1 | flat: lightgreyflatlightgrey -------------------------------------------------------------------------------- /.github/images/flat_orange.svg: -------------------------------------------------------------------------------- 1 | flat: orangeflatorange -------------------------------------------------------------------------------- /.github/images/flat_red.svg: -------------------------------------------------------------------------------- 1 | flat: redflatred -------------------------------------------------------------------------------- /.github/images/flat_simple_blue.svg: -------------------------------------------------------------------------------- 1 | blueblue -------------------------------------------------------------------------------- /.github/images/flat_simple_brightgreen.svg: -------------------------------------------------------------------------------- 1 | brightgreenbrightgreen -------------------------------------------------------------------------------- /.github/images/flat_simple_critical.svg: -------------------------------------------------------------------------------- 1 | criticalcritical -------------------------------------------------------------------------------- /.github/images/flat_simple_custom.svg: -------------------------------------------------------------------------------- 1 | #ff69b4#ff69b4 -------------------------------------------------------------------------------- /.github/images/flat_simple_green.svg: -------------------------------------------------------------------------------- 1 | greengreen -------------------------------------------------------------------------------- /.github/images/flat_simple_important.svg: -------------------------------------------------------------------------------- 1 | importantimportant -------------------------------------------------------------------------------- /.github/images/flat_simple_inactive.svg: -------------------------------------------------------------------------------- 1 | inactiveinactive -------------------------------------------------------------------------------- /.github/images/flat_simple_informational.svg: -------------------------------------------------------------------------------- 1 | informationalinformational -------------------------------------------------------------------------------- /.github/images/flat_simple_japanese.svg: -------------------------------------------------------------------------------- 1 | メッセージメッセージ -------------------------------------------------------------------------------- /.github/images/flat_simple_lightgrey.svg: -------------------------------------------------------------------------------- 1 | lightgreylightgrey -------------------------------------------------------------------------------- /.github/images/flat_simple_orange.svg: -------------------------------------------------------------------------------- 1 | orangeorange -------------------------------------------------------------------------------- /.github/images/flat_simple_red.svg: -------------------------------------------------------------------------------- 1 | redred -------------------------------------------------------------------------------- /.github/images/flat_simple_success.svg: -------------------------------------------------------------------------------- 1 | successsuccess -------------------------------------------------------------------------------- /.github/images/flat_simple_yellow.svg: -------------------------------------------------------------------------------- 1 | yellowyellow -------------------------------------------------------------------------------- /.github/images/flat_simple_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | yellowgreenyellowgreen -------------------------------------------------------------------------------- /.github/images/flat_success.svg: -------------------------------------------------------------------------------- 1 | flat: successflatsuccess -------------------------------------------------------------------------------- /.github/images/flat_yellow.svg: -------------------------------------------------------------------------------- 1 | flat: yellowflatyellow -------------------------------------------------------------------------------- /.github/images/flat_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | flat: yellowgreenflatyellowgreen -------------------------------------------------------------------------------- /.github/images/godoc.svg: -------------------------------------------------------------------------------- 1 | go: referencegoreference -------------------------------------------------------------------------------- /.github/images/license.svg: -------------------------------------------------------------------------------- 1 | license: Apache-2.0licenseApache-2.0 -------------------------------------------------------------------------------- /.github/images/plastic_blue.svg: -------------------------------------------------------------------------------- 1 | plastic: blueplasticblue -------------------------------------------------------------------------------- /.github/images/plastic_brightgreen.svg: -------------------------------------------------------------------------------- 1 | plastic: brightgreenplasticbrightgreen -------------------------------------------------------------------------------- /.github/images/plastic_critical.svg: -------------------------------------------------------------------------------- 1 | plastic: criticalplasticcritical -------------------------------------------------------------------------------- /.github/images/plastic_custom.svg: -------------------------------------------------------------------------------- 1 | plastic: #ff69b4plastic#ff69b4 -------------------------------------------------------------------------------- /.github/images/plastic_green.svg: -------------------------------------------------------------------------------- 1 | plastic: greenplasticgreen -------------------------------------------------------------------------------- /.github/images/plastic_important.svg: -------------------------------------------------------------------------------- 1 | plastic: importantplasticimportant -------------------------------------------------------------------------------- /.github/images/plastic_inactive.svg: -------------------------------------------------------------------------------- 1 | plastic: inactiveplasticinactive -------------------------------------------------------------------------------- /.github/images/plastic_informational.svg: -------------------------------------------------------------------------------- 1 | plastic: informationalplasticinformational -------------------------------------------------------------------------------- /.github/images/plastic_japanese.svg: -------------------------------------------------------------------------------- 1 | ラベル: メッセージラベルメッセージ -------------------------------------------------------------------------------- /.github/images/plastic_lightgrey.svg: -------------------------------------------------------------------------------- 1 | plastic: lightgreyplasticlightgrey -------------------------------------------------------------------------------- /.github/images/plastic_orange.svg: -------------------------------------------------------------------------------- 1 | plastic: orangeplasticorange -------------------------------------------------------------------------------- /.github/images/plastic_red.svg: -------------------------------------------------------------------------------- 1 | plastic: redplasticred -------------------------------------------------------------------------------- /.github/images/plastic_simple_blue.svg: -------------------------------------------------------------------------------- 1 | TESTTESTblue -------------------------------------------------------------------------------- /.github/images/plastic_simple_brightgreen.svg: -------------------------------------------------------------------------------- 1 | TESTTESTbrightgreen -------------------------------------------------------------------------------- /.github/images/plastic_simple_critical.svg: -------------------------------------------------------------------------------- 1 | TESTTESTcritical -------------------------------------------------------------------------------- /.github/images/plastic_simple_custom.svg: -------------------------------------------------------------------------------- 1 | TESTTEST#ff69b4 -------------------------------------------------------------------------------- /.github/images/plastic_simple_green.svg: -------------------------------------------------------------------------------- 1 | TESTTESTgreen -------------------------------------------------------------------------------- /.github/images/plastic_simple_important.svg: -------------------------------------------------------------------------------- 1 | TESTTESTimportant -------------------------------------------------------------------------------- /.github/images/plastic_simple_inactive.svg: -------------------------------------------------------------------------------- 1 | TESTTESTinactive -------------------------------------------------------------------------------- /.github/images/plastic_simple_informational.svg: -------------------------------------------------------------------------------- 1 | TESTTESTinformational -------------------------------------------------------------------------------- /.github/images/plastic_simple_japanese.svg: -------------------------------------------------------------------------------- 1 | TESTTESTメッセージ -------------------------------------------------------------------------------- /.github/images/plastic_simple_lightgrey.svg: -------------------------------------------------------------------------------- 1 | TESTTESTlightgrey -------------------------------------------------------------------------------- /.github/images/plastic_simple_orange.svg: -------------------------------------------------------------------------------- 1 | TESTTESTorange -------------------------------------------------------------------------------- /.github/images/plastic_simple_red.svg: -------------------------------------------------------------------------------- 1 | TESTTESTred -------------------------------------------------------------------------------- /.github/images/plastic_simple_success.svg: -------------------------------------------------------------------------------- 1 | TESTTESTsuccess -------------------------------------------------------------------------------- /.github/images/plastic_simple_yellow.svg: -------------------------------------------------------------------------------- 1 | TESTTESTyellow -------------------------------------------------------------------------------- /.github/images/plastic_simple_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | TESTTESTyellowgreen -------------------------------------------------------------------------------- /.github/images/plastic_success.svg: -------------------------------------------------------------------------------- 1 | plastic: successplasticsuccess -------------------------------------------------------------------------------- /.github/images/plastic_yellow.svg: -------------------------------------------------------------------------------- 1 | plastic: yellowplasticyellow -------------------------------------------------------------------------------- /.github/images/plastic_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | plastic: yellowgreenplasticyellowgreen -------------------------------------------------------------------------------- /.github/images/square_blue.svg: -------------------------------------------------------------------------------- 1 | square: bluesquareblue -------------------------------------------------------------------------------- /.github/images/square_brightgreen.svg: -------------------------------------------------------------------------------- 1 | square: brightgreensquarebrightgreen -------------------------------------------------------------------------------- /.github/images/square_critical.svg: -------------------------------------------------------------------------------- 1 | square: criticalsquarecritical -------------------------------------------------------------------------------- /.github/images/square_custom.svg: -------------------------------------------------------------------------------- 1 | square: #ff69b4square#ff69b4 -------------------------------------------------------------------------------- /.github/images/square_green.svg: -------------------------------------------------------------------------------- 1 | square: greensquaregreen -------------------------------------------------------------------------------- /.github/images/square_important.svg: -------------------------------------------------------------------------------- 1 | square: importantsquareimportant -------------------------------------------------------------------------------- /.github/images/square_inactive.svg: -------------------------------------------------------------------------------- 1 | square: inactivesquareinactive -------------------------------------------------------------------------------- /.github/images/square_informational.svg: -------------------------------------------------------------------------------- 1 | square: informationalsquareinformational -------------------------------------------------------------------------------- /.github/images/square_japanese.svg: -------------------------------------------------------------------------------- 1 | ラベル: メッセージラベルメッセージ -------------------------------------------------------------------------------- /.github/images/square_lightgrey.svg: -------------------------------------------------------------------------------- 1 | square: lightgreysquarelightgrey -------------------------------------------------------------------------------- /.github/images/square_orange.svg: -------------------------------------------------------------------------------- 1 | square: orangesquareorange -------------------------------------------------------------------------------- /.github/images/square_red.svg: -------------------------------------------------------------------------------- 1 | square: redsquarered -------------------------------------------------------------------------------- /.github/images/square_simple_blue.svg: -------------------------------------------------------------------------------- 1 | blueblue -------------------------------------------------------------------------------- /.github/images/square_simple_brightgreen.svg: -------------------------------------------------------------------------------- 1 | brightgreenbrightgreen -------------------------------------------------------------------------------- /.github/images/square_simple_critical.svg: -------------------------------------------------------------------------------- 1 | criticalcritical -------------------------------------------------------------------------------- /.github/images/square_simple_custom.svg: -------------------------------------------------------------------------------- 1 | #ff69b4#ff69b4 -------------------------------------------------------------------------------- /.github/images/square_simple_green.svg: -------------------------------------------------------------------------------- 1 | greengreen -------------------------------------------------------------------------------- /.github/images/square_simple_important.svg: -------------------------------------------------------------------------------- 1 | importantimportant -------------------------------------------------------------------------------- /.github/images/square_simple_inactive.svg: -------------------------------------------------------------------------------- 1 | inactiveinactive -------------------------------------------------------------------------------- /.github/images/square_simple_informational.svg: -------------------------------------------------------------------------------- 1 | informationalinformational -------------------------------------------------------------------------------- /.github/images/square_simple_japanese.svg: -------------------------------------------------------------------------------- 1 | メッセージメッセージ -------------------------------------------------------------------------------- /.github/images/square_simple_lightgrey.svg: -------------------------------------------------------------------------------- 1 | lightgreylightgrey -------------------------------------------------------------------------------- /.github/images/square_simple_orange.svg: -------------------------------------------------------------------------------- 1 | orangeorange -------------------------------------------------------------------------------- /.github/images/square_simple_red.svg: -------------------------------------------------------------------------------- 1 | redred -------------------------------------------------------------------------------- /.github/images/square_simple_success.svg: -------------------------------------------------------------------------------- 1 | successsuccess -------------------------------------------------------------------------------- /.github/images/square_simple_yellow.svg: -------------------------------------------------------------------------------- 1 | yellowyellow -------------------------------------------------------------------------------- /.github/images/square_simple_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | yellowgreenyellowgreen -------------------------------------------------------------------------------- /.github/images/square_success.svg: -------------------------------------------------------------------------------- 1 | square: successsquaresuccess -------------------------------------------------------------------------------- /.github/images/square_yellow.svg: -------------------------------------------------------------------------------- 1 | square: yellowsquareyellow -------------------------------------------------------------------------------- /.github/images/square_yellowgreen.svg: -------------------------------------------------------------------------------- 1 | square: yellowgreensquareyellowgreen -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master, develop] 6 | pull_request: 7 | branches: [master] 8 | workflow_dispatch: 9 | inputs: 10 | force_run: 11 | description: 'Force workflow run' 12 | required: true 13 | type: choice 14 | options: [yes, no] 15 | 16 | permissions: 17 | actions: read 18 | contents: read 19 | statuses: write 20 | 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | 25 | jobs: 26 | Go: 27 | name: Go 28 | runs-on: ubuntu-latest 29 | 30 | strategy: 31 | matrix: 32 | go: [ 'oldstable', 'stable' ] 33 | 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v4 37 | 38 | - name: Set up Go 39 | uses: actions/setup-go@v5 40 | with: 41 | go-version: ${{ matrix.go }} 42 | 43 | - name: Download dependencies 44 | run: make deps 45 | 46 | - name: Download Verdana font 47 | run: curl -L -o 'Verdana.ttf' 'https://github.com/matomo-org/travis-scripts/raw/master/fonts/Verdana.ttf' 48 | 49 | - name: Run tests 50 | run: go test -v -covermode count -coverprofile cover.out ./... 51 | 52 | - name: Send coverage data to Coveralls 53 | uses: essentialkaos/goveralls-action@v2 54 | env: 55 | COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 56 | with: 57 | profile: cover.out 58 | parallel: true 59 | flag-name: linux-${{ matrix.go }} 60 | 61 | - name: Send coverage data to Codacy 62 | env: 63 | CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} 64 | run: | 65 | bash <(curl -Ls https://coverage.codacy.com/get.sh) report \ 66 | --force-coverage-parser go \ 67 | -r cover.out \ 68 | --partial 69 | 70 | SendCoverage: 71 | name: Send Coverage 72 | runs-on: ubuntu-latest 73 | 74 | needs: Go 75 | 76 | steps: 77 | - name: Finish parallel tests (Coveralls) 78 | uses: essentialkaos/goveralls-action@v2 79 | env: 80 | COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 81 | with: 82 | parallel-finished: true 83 | 84 | - name: Finish parallel tests (Codacy) 85 | env: 86 | CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} 87 | run: bash <(curl -Ls https://coverage.codacy.com/get.sh) final 88 | 89 | Aligo: 90 | name: Aligo 91 | runs-on: ubuntu-latest 92 | 93 | needs: Go 94 | 95 | steps: 96 | - name: Checkout 97 | uses: actions/checkout@v4 98 | 99 | - name: Set up Go 100 | uses: actions/setup-go@v5 101 | with: 102 | go-version: 'stable' 103 | 104 | - name: Download dependencies 105 | run: make deps 106 | 107 | - name: Check Golang sources with Aligo 108 | uses: essentialkaos/aligo-action@v2 109 | continue-on-error: true 110 | with: 111 | files: ./... 112 | 113 | Typos: 114 | name: Typos 115 | runs-on: ubuntu-latest 116 | 117 | needs: Go 118 | 119 | steps: 120 | - name: Checkout 121 | uses: actions/checkout@v4 122 | 123 | - name: Check spelling 124 | uses: crate-ci/typos@master 125 | continue-on-error: true 126 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [master, develop] 6 | pull_request: 7 | branches: [master] 8 | schedule: 9 | - cron: '0 3 * * */2' 10 | 11 | permissions: 12 | security-events: write 13 | actions: read 14 | contents: read 15 | 16 | jobs: 17 | analyse: 18 | name: Analyse 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - name: Checkout repository 23 | uses: actions/checkout@v4 24 | with: 25 | fetch-depth: 2 26 | 27 | - name: Initialize CodeQL 28 | uses: github/codeql-action/init@v3 29 | with: 30 | languages: go 31 | 32 | - name: Perform CodeQL Analysis 33 | uses: github/codeql-action/analyze@v3 34 | -------------------------------------------------------------------------------- /.github/workflows/godoc.yml: -------------------------------------------------------------------------------- 1 | name: GoDoc 2 | 3 | on: 4 | create 5 | 6 | jobs: 7 | GoDoc: 8 | name: Generate docs 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Trigger GoSumDB and PkgGoDev 13 | uses: essentialkaos/godoc-action@v1 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Verdana.ttf 2 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | [files] 2 | extend-exclude = ["go.sum"] 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 ESSENTIAL KAOS 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | 3 | # This Makefile generated by GoMakeGen 3.3.1 using next command: 4 | # gomakegen --mod . 5 | # 6 | # More info: https://kaos.sh/gomakegen 7 | 8 | ################################################################################ 9 | 10 | ifdef VERBOSE ## Print verbose information (Flag) 11 | VERBOSE_FLAG = -v 12 | endif 13 | 14 | ifdef PROXY ## Force proxy usage for downloading dependencies (Flag) 15 | export GOPROXY=https://proxy.golang.org/cached-only,direct 16 | endif 17 | 18 | ifdef CGO ## Enable CGO usage (Flag) 19 | export CGO_ENABLED=1 20 | else 21 | export CGO_ENABLED=0 22 | endif 23 | 24 | MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) 25 | GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) 26 | 27 | ################################################################################ 28 | 29 | .DEFAULT_GOAL := help 30 | .PHONY = fmt vet deps update test init vendor tidy mod-init mod-update mod-download mod-vendor help 31 | 32 | ################################################################################ 33 | 34 | init: mod-init ## Initialize new module 35 | 36 | deps: mod-download ## Download dependencies 37 | 38 | update: mod-update ## Update dependencies to the latest versions 39 | 40 | vendor: mod-vendor ## Make vendored copy of dependencies 41 | 42 | test: ## Run tests 43 | @echo "Starting tests…" 44 | ifdef COVERAGE_FILE ## Save coverage data into file (String) 45 | @go test $(VERBOSE_FLAG) -covermode=count -coverprofile=$(COVERAGE_FILE) ./. 46 | else 47 | @go test $(VERBOSE_FLAG) -covermode=count . 48 | endif 49 | 50 | tidy: ## Cleanup dependencies 51 | @echo "•• Tidying up dependencies…" 52 | ifdef COMPAT ## Compatible Go version (String) 53 | @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) 54 | else 55 | @go mod tidy $(VERBOSE_FLAG) 56 | endif 57 | @echo "•• Updating vendored dependencies…" 58 | @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : 59 | 60 | mod-init: 61 | @echo "••• Modules initialization…" 62 | @rm -f go.mod go.sum 63 | ifdef MODULE_PATH ## Module path for initialization (String) 64 | @go mod init $(MODULE_PATH) 65 | else 66 | @go mod init 67 | endif 68 | 69 | @echo "••• Dependencies cleanup…" 70 | ifdef COMPAT ## Compatible Go version (String) 71 | @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) 72 | else 73 | @go mod tidy $(VERBOSE_FLAG) 74 | endif 75 | @echo "••• Stripping toolchain info…" 76 | @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : 77 | 78 | mod-update: 79 | @echo "•••• Updating dependencies…" 80 | ifdef UPDATE_ALL ## Update all dependencies (Flag) 81 | @go get -u $(VERBOSE_FLAG) all 82 | else 83 | @go get -u $(VERBOSE_FLAG) ./... 84 | endif 85 | 86 | @echo "•••• Stripping toolchain info…" 87 | @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : 88 | 89 | @echo "•••• Dependencies cleanup…" 90 | ifdef COMPAT 91 | @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) 92 | else 93 | @go mod tidy $(VERBOSE_FLAG) 94 | endif 95 | 96 | @echo "•••• Updating vendored dependencies…" 97 | @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : 98 | 99 | mod-download: 100 | @echo "Downloading dependencies…" 101 | @go mod download 102 | 103 | mod-vendor: 104 | @echo "Vendoring dependencies…" 105 | @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : 106 | 107 | fmt: ## Format source code with gofmt 108 | @echo "Formatting sources…" 109 | @find . -name "*.go" -exec gofmt -s -w {} \; 110 | 111 | vet: ## Runs 'go vet' over sources 112 | @echo "Running 'go vet' over sources…" 113 | @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... 114 | 115 | help: ## Show this info 116 | @echo -e '\n\033[1mTargets:\033[0m\n' 117 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ 118 | | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-6s\033[0m %s\n", $$1, $$2}' 119 | @echo -e '\n\033[1mVariables:\033[0m\n' 120 | @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ 121 | | sed 's/ifdef //' \ 122 | | sort -h \ 123 | | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-13s\033[0m %s\n", $$1, $$2}' 124 | @echo -e '' 125 | @echo -e '\033[90mGenerated by GoMakeGen 3.3.1\033[0m\n' 126 | 127 | ################################################################################ 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | GitHub Actions CI Status 6 | GoReportCard 7 | Coverage Status
8 | Codacy badge 9 | GitHub Actions CodeQL Status 10 | 11 |

12 | 13 |

Usage exampleExamplesCI StatusContributingThanksLicense

14 | 15 |
16 | 17 | `badge` is a Go package for generating SVG badges. 18 | 19 | ### Usage example 20 | 21 | ```go 22 | package main 23 | 24 | // ////////////////////////////////////////////////////////////////////////// // 25 | 26 | import ( 27 | "fmt" 28 | "github.com/essentialkaos/go-badge" 29 | ) 30 | 31 | // ////////////////////////////////////////////////////////////////////////// // 32 | 33 | func main() { 34 | g, err := badge.NewGenerator("/path/to/Verdana.ttf", 11) 35 | 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | fmt.Println(string(g.GeneratePlastic("status", "ok", "#97ca00"))) 41 | } 42 | ``` 43 | 44 | ### Examples 45 | 46 | | Flat | Flat Square | Plastic | Flat (Simple) | Flat Square (Simple) | Plastic (Simple) | 47 | |------|-------------|---------|---------------|----------------------|------------------| 48 | | ![flat](.github/images/flat_brightgreen.svg) | ![square](.github/images/square_brightgreen.svg) | ![plastic](.github/images/plastic_brightgreen.svg) | ![flat-simple](.github/images/flat_simple_brightgreen.svg) | ![square-simple](.github/images/square_simple_brightgreen.svg) | ![plastic-simple](.github/images/plastic_simple_brightgreen.svg) | 49 | | ![flat](.github/images/flat_green.svg) | ![square](.github/images/square_green.svg) | ![plastic](.github/images/plastic_green.svg) | ![flat-simple](.github/images/flat_simple_green.svg) | ![square-simple](.github/images/square_simple_green.svg) | ![plastic-simple](.github/images/plastic_simple_green.svg) | 50 | | ![flat](.github/images/flat_yellowgreen.svg) | ![square](.github/images/square_yellowgreen.svg) | ![plastic](.github/images/plastic_yellowgreen.svg) | ![flat-simple](.github/images/flat_simple_yellowgreen.svg) | ![square-simple](.github/images/square_simple_yellowgreen.svg) | ![plastic-simple](.github/images/plastic_simple_yellowgreen.svg) | 51 | | ![flat](.github/images/flat_yellow.svg) | ![square](.github/images/square_yellow.svg) | ![plastic](.github/images/plastic_yellow.svg) | ![flat-simple](.github/images/flat_simple_yellow.svg) | ![square-simple](.github/images/square_simple_yellow.svg) | ![plastic-simple](.github/images/plastic_simple_yellow.svg) | 52 | | ![flat](.github/images/flat_orange.svg) | ![square](.github/images/square_orange.svg) | ![plastic](.github/images/plastic_orange.svg) | ![flat-simple](.github/images/flat_simple_orange.svg) | ![square-simple](.github/images/square_simple_orange.svg) | ![plastic-simple](.github/images/plastic_simple_orange.svg) | 53 | | ![flat](.github/images/flat_red.svg) | ![square](.github/images/square_red.svg) | ![plastic](.github/images/plastic_red.svg) | ![flat-simple](.github/images/flat_simple_red.svg) | ![square-simple](.github/images/square_simple_red.svg) | ![plastic-simple](.github/images/plastic_simple_red.svg) | 54 | | ![flat](.github/images/flat_blue.svg) | ![square](.github/images/square_blue.svg) | ![plastic](.github/images/plastic_blue.svg) | ![flat-simple](.github/images/flat_simple_blue.svg) | ![square-simple](.github/images/square_simple_blue.svg) | ![plastic-simple](.github/images/plastic_simple_blue.svg) | 55 | | ![flat](.github/images/flat_lightgrey.svg) | ![square](.github/images/square_lightgrey.svg) | ![plastic](.github/images/plastic_lightgrey.svg) | ![flat-simple](.github/images/flat_simple_lightgrey.svg) | ![square-simple](.github/images/square_simple_lightgrey.svg) | ![plastic-simple](.github/images/plastic_simple_lightgrey.svg) | 56 | | ![flat](.github/images/flat_success.svg) | ![square](.github/images/square_success.svg) | ![plastic](.github/images/plastic_success.svg) | ![flat-simple](.github/images/flat_simple_success.svg) | ![square-simple](.github/images/square_simple_success.svg) | ![plastic-simple](.github/images/plastic_simple_success.svg) | 57 | | ![flat](.github/images/flat_important.svg) | ![square](.github/images/square_important.svg) | ![plastic](.github/images/plastic_important.svg) | ![flat-simple](.github/images/flat_simple_important.svg) | ![square-simple](.github/images/square_simple_important.svg) | ![plastic-simple](.github/images/plastic_simple_important.svg) | 58 | | ![flat](.github/images/flat_critical.svg) | ![square](.github/images/square_critical.svg) | ![plastic](.github/images/plastic_critical.svg) | ![flat-simple](.github/images/flat_simple_critical.svg) | ![square-simple](.github/images/square_simple_critical.svg) | ![plastic-simple](.github/images/plastic_simple_critical.svg) | 59 | | ![flat](.github/images/flat_informational.svg) | ![square](.github/images/square_informational.svg) | ![plastic](.github/images/plastic_informational.svg) | ![flat-simple](.github/images/flat_simple_informational.svg) | ![square-simple](.github/images/square_simple_informational.svg) | ![plastic-simple](.github/images/plastic_simple_informational.svg) | 60 | | ![flat](.github/images/flat_inactive.svg) | ![square](.github/images/square_inactive.svg) | ![plastic](.github/images/plastic_inactive.svg) | ![flat-simple](.github/images/flat_simple_inactive.svg) | ![square-simple](.github/images/square_simple_inactive.svg) | ![plastic-simple](.github/images/plastic_simple_inactive.svg) | 61 | | ![flat](.github/images/flat_custom.svg) | ![square](.github/images/square_custom.svg) | ![plastic](.github/images/plastic_custom.svg) | ![flat-simple](.github/images/flat_simple_custom.svg) | ![square-simple](.github/images/square_simple_custom.svg) | ![plastic-simple](.github/images/plastic_simple_custom.svg) | 62 | | ![flat](.github/images/flat_japanese.svg) | ![square](.github/images/square_japanese.svg) | ![plastic](.github/images/plastic_japanese.svg) | ![flat-simple](.github/images/flat_simple_japanese.svg) | ![square-simple](.github/images/square_simple_japanese.svg) | ![plastic-simple](.github/images/plastic_simple_japanese.svg) | 63 | 64 | _All badges are generated with the latest version of the package._ 65 | 66 | ### CI Status 67 | 68 | | Branch | Status | 69 | |--------|----------| 70 | | `master` | [![CI](https://kaos.sh/w/go-badge/ci.svg?branch=master)](https://kaos.sh/w/go-badge/ci?query=branch:master) | 71 | | `develop` | [![CI](https://kaos.sh/w/go-badge/ci.svg?branch=develop)](https://kaos.sh/w/go-badge/ci?query=branch:develop) | 72 | 73 | ### Contributing 74 | 75 | Before contributing to this project please read our [Contributing Guidelines](https://github.com/essentialkaos/.github/blob/master/CONTRIBUTING.md). 76 | 77 | ### Thanks 78 | 79 | We would like to thank: 80 | 81 | * All authors and [contributors](https://github.com/badges/shields/graphs/contributors) of [shields.io](https://shields.io) service; 82 | * All authors of [`freetype`](https://github.com/golang/freetype/blob/master/AUTHORS) package; 83 | * [@narqo](https://github.com/narqo) for [`go-badge`](https://github.com/narqo/go-badge) package. 84 | 85 | ### License 86 | 87 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 88 | 89 |

90 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policies and Procedures 2 | 3 | This document outlines security procedures and general policies for all 4 | ESSENTIAL KAOS projects. 5 | 6 | * [Reporting a Bug](#reporting-a-bug) 7 | * [Disclosure Policy](#disclosure-policy) 8 | 9 | ## Reporting a Bug 10 | 11 | The ESSENTIAL KAOS team and community take all security bugs in our projects 12 | very seriously. Thank you for improving the security of our project. We 13 | appreciate your efforts and responsible disclosure and will make every effort 14 | to acknowledge your contributions. 15 | 16 | Report security bugs by emailing our security team at security@essentialkaos.com. 17 | 18 | The security team will acknowledge your email within 48 hours and will send a 19 | more detailed response within 48 hours, indicating the next steps in handling 20 | your report. After the initial reply to your report, the security team will 21 | endeavor to keep you informed of the progress towards a fix and full 22 | announcement, and may ask for additional information or guidance. 23 | 24 | Report security bugs in third-party dependencies to the person or team 25 | maintaining the dependencies. 26 | 27 | ## Disclosure Policy 28 | 29 | When the security team receives a security bug report, they will assign it to a 30 | primary handler. This person will coordinate the fix and release process, 31 | involving the following steps: 32 | 33 | * Confirm the problem and determine the affected versions; 34 | * Audit code to find any similar potential problems; 35 | * Prepare fixes for all releases still under maintenance. These fixes will be 36 | released as fast as possible. 37 | -------------------------------------------------------------------------------- /badge.go: -------------------------------------------------------------------------------- 1 | // Package badge provides methods for generating SVG badges 2 | package badge 3 | 4 | // ////////////////////////////////////////////////////////////////////////////////// // 5 | // // 6 | // Copyright (c) 2024 ESSENTIAL KAOS // 7 | // Apache License, Version 2.0 // 8 | // // 9 | // ////////////////////////////////////////////////////////////////////////////////// // 10 | 11 | import ( 12 | "fmt" 13 | "io" 14 | "math" 15 | "os" 16 | "strconv" 17 | "strings" 18 | 19 | "github.com/golang/freetype/truetype" 20 | 21 | "golang.org/x/image/font" 22 | ) 23 | 24 | // ////////////////////////////////////////////////////////////////////////////////// // 25 | 26 | const ( 27 | COLOR_BLUE = "#007ec6" 28 | COLOR_BRIGHTGREEN = "#4c1" 29 | COLOR_GREEN = "#97ca00" 30 | COLOR_GREY = "#555" 31 | COLOR_LIGHTGREY = "#9f9f9f" 32 | COLOR_ORANGE = "#fe7d37" 33 | COLOR_RED = "#e05d44" 34 | COLOR_YELLOW = "#dfb317" 35 | COLOR_YELLOWGREEN = "#a4a61d" 36 | 37 | COLOR_SUCCESS = "#4c1" 38 | COLOR_IMPORTANT = "#fe7d37" 39 | COLOR_CRITICAL = "#e05d44" 40 | COLOR_INFORMATIONAL = "#007ec6" 41 | COLOR_INACTIVE = "#9f9f9f" 42 | ) 43 | 44 | const ( 45 | DEFAULT_OFFSET = 9 // default font offset 46 | DEFAULT_SPACING = 0 // default letter spacing 47 | ) 48 | 49 | // ////////////////////////////////////////////////////////////////////////////////// // 50 | 51 | const _TEMPLATE_PLASTIC = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` 52 | 53 | const _TEMPLATE_FLAT = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` 54 | 55 | const _TEMPLATE_FLAT_SQUARE = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` 56 | 57 | const _TEMPLATE_FLAT_SIMPLE = `{MESSAGE}{MESSAGE}` 58 | 59 | const _TEMPLATE_PLASTIC_SIMPLE = `TESTTEST{MESSAGE}` 60 | 61 | const _TEMPLATE_FLAT_SQUARE_SIMPLE = `{MESSAGE}{MESSAGE}` 62 | 63 | // ////////////////////////////////////////////////////////////////////////////////// // 64 | 65 | // Generator is badge generator 66 | type Generator struct { 67 | Offset int // Text offset 68 | Spacing float64 // Letter spacing 69 | 70 | fontSize int 71 | fontName string 72 | drawer *font.Drawer 73 | } 74 | 75 | // ////////////////////////////////////////////////////////////////////////////////// // 76 | 77 | // NewGenerator creates new badge generator using given path to font file 78 | func NewGenerator(fontFile string, fontSize int) (*Generator, error) { 79 | data, err := os.ReadFile(fontFile) 80 | 81 | if err != nil { 82 | return nil, fmt.Errorf("Can't read font data: %w", err) 83 | } 84 | 85 | return NewGeneratorFromBytes(data, fontSize) 86 | } 87 | 88 | // NewGeneratorFromReader creates a new card generator using a reader that provides font 89 | // data 90 | func NewGeneratorFromReader(r io.Reader, fontSize int) (*Generator, error) { 91 | fontData, err := io.ReadAll(r) 92 | 93 | if err != nil { 94 | return nil, fmt.Errorf("Can't read font data: %w", err) 95 | } 96 | 97 | return NewGeneratorFromBytes(fontData, fontSize) 98 | } 99 | 100 | // NewGeneratorFromBytes creates a new card generator using given font data 101 | func NewGeneratorFromBytes(fontData []byte, fontSize int) (*Generator, error) { 102 | fontTTF, err := truetype.Parse(fontData) 103 | 104 | if err != nil { 105 | return nil, err 106 | } 107 | 108 | return &Generator{ 109 | Offset: DEFAULT_OFFSET, 110 | Spacing: DEFAULT_SPACING, 111 | 112 | fontSize: fontSize, 113 | 114 | fontName: fontTTF.Name(truetype.NameIDFontFullName), 115 | drawer: &font.Drawer{ 116 | Face: truetype.NewFace(fontTTF, &truetype.Options{ 117 | Size: float64(fontSize), 118 | DPI: 72, 119 | Hinting: font.HintingFull, 120 | }), 121 | }, 122 | }, nil 123 | } 124 | 125 | // ////////////////////////////////////////////////////////////////////////////////// // 126 | 127 | // GeneratePlastic generates SVG badge in plastic style 128 | func (g *Generator) GeneratePlastic(label, message, color string) []byte { 129 | if label == "" { 130 | return g.generateBadgeSimple(_TEMPLATE_PLASTIC_SIMPLE, message, color) 131 | } 132 | 133 | return g.generateBadge(_TEMPLATE_PLASTIC, label, message, color) 134 | } 135 | 136 | // GenerateFlat generates SVG badge in flat style 137 | func (g *Generator) GenerateFlat(label, message, color string) []byte { 138 | if label == "" { 139 | return g.generateBadgeSimple(_TEMPLATE_FLAT_SIMPLE, message, color) 140 | } 141 | 142 | return g.generateBadge(_TEMPLATE_FLAT, label, message, color) 143 | } 144 | 145 | // GenerateFlatSquare generates SVG badge in flat-square style 146 | func (g *Generator) GenerateFlatSquare(label, message, color string) []byte { 147 | if label == "" { 148 | return g.generateBadgeSimple(_TEMPLATE_FLAT_SQUARE_SIMPLE, message, color) 149 | } 150 | 151 | return g.generateBadge(_TEMPLATE_FLAT_SQUARE, label, message, color) 152 | } 153 | 154 | // GeneratePlasticSimple generates SVG simple badge in plastic style 155 | func (g *Generator) GeneratePlasticSimple(message, color string) []byte { 156 | return g.generateBadgeSimple(_TEMPLATE_PLASTIC_SIMPLE, message, color) 157 | } 158 | 159 | // GenerateFlatSimple generates SVG simple badge in flat style 160 | func (g *Generator) GenerateFlatSimple(message, color string) []byte { 161 | return g.generateBadgeSimple(_TEMPLATE_FLAT_SIMPLE, message, color) 162 | } 163 | 164 | // GenerateFlatSquareSimple generates SVG simple badge in flat-square style 165 | func (g *Generator) GenerateFlatSquareSimple(message, color string) []byte { 166 | return g.generateBadgeSimple(_TEMPLATE_FLAT_SQUARE_SIMPLE, message, color) 167 | } 168 | 169 | // ////////////////////////////////////////////////////////////////////////////////// // 170 | 171 | // generateBadge generates badge with given template 172 | func (g *Generator) generateBadge(template, label, message, color string) []byte { 173 | c := parseColor(color) 174 | 175 | gF := float64(g.Offset) 176 | lW := float64(g.drawer.MeasureString(label)>>6) + gF 177 | mW := float64(g.drawer.MeasureString(message)>>6) + gF 178 | fW := lW + mW 179 | lX := (lW/2 + 1) * 10 180 | mX := (lW + (mW / 2) - 1) * 10 181 | lL := (lW - gF) * (10.0 + g.Spacing - 0.5) 182 | mL := (mW - gF) * (10.0 + g.Spacing - 0.5) 183 | fS := g.fontSize * 10 184 | 185 | mC, mS := getMessageColors(c) 186 | 187 | badge := strings.ReplaceAll(template, "{LABEL}", label) 188 | badge = strings.ReplaceAll(badge, "{MESSAGE}", message) 189 | badge = strings.ReplaceAll(badge, "{COLOR}", formatColor(c)) 190 | badge = strings.ReplaceAll(badge, "{WIDTH}", formatFloat(fW)) 191 | badge = strings.ReplaceAll(badge, "{LABEL_WIDTH}", formatFloat(lW)) 192 | badge = strings.ReplaceAll(badge, "{MESSAGE_WIDTH}", formatFloat(mW)) 193 | badge = strings.ReplaceAll(badge, "{LABEL_X}", formatFloat(lX)) 194 | badge = strings.ReplaceAll(badge, "{MESSAGE_X}", formatFloat(mX)) 195 | badge = strings.ReplaceAll(badge, "{LABEL_LENGTH}", formatFloat(lL)) 196 | badge = strings.ReplaceAll(badge, "{MESSAGE_LENGTH}", formatFloat(mL)) 197 | badge = strings.ReplaceAll(badge, "{MESSAGE_COLOR}", mC) 198 | badge = strings.ReplaceAll(badge, "{MESSAGE_SHADOW}", mS) 199 | badge = strings.ReplaceAll(badge, "{FONT}", g.fontName) 200 | badge = strings.ReplaceAll(badge, "{FONT_SIZE}", strconv.Itoa(fS)) 201 | 202 | return []byte(badge) 203 | } 204 | 205 | // generateBadgeSimple generates badge with given template 206 | func (g *Generator) generateBadgeSimple(template, message, color string) []byte { 207 | c := parseColor(color) 208 | 209 | gF := float64(g.Offset) 210 | fW := float64(g.drawer.MeasureString(message)>>6) + gF 211 | mX := (fW / 2) * 10 212 | mL := (fW - gF) * (10.0 + g.Spacing) 213 | fS := g.fontSize * 10 214 | 215 | mC, mS := getMessageColors(c) 216 | 217 | badge := strings.ReplaceAll(template, "{MESSAGE}", message) 218 | badge = strings.ReplaceAll(badge, "{COLOR}", formatColor(c)) 219 | badge = strings.ReplaceAll(badge, "{WIDTH}", formatFloat(fW)) 220 | badge = strings.ReplaceAll(badge, "{MESSAGE_X}", formatFloat(mX)) 221 | badge = strings.ReplaceAll(badge, "{MESSAGE_LENGTH}", formatFloat(mL)) 222 | badge = strings.ReplaceAll(badge, "{MESSAGE_COLOR}", mC) 223 | badge = strings.ReplaceAll(badge, "{MESSAGE_SHADOW}", mS) 224 | badge = strings.ReplaceAll(badge, "{FONT}", g.fontName) 225 | badge = strings.ReplaceAll(badge, "{FONT_SIZE}", strconv.Itoa(fS)) 226 | 227 | return []byte(badge) 228 | } 229 | 230 | // ////////////////////////////////////////////////////////////////////////////////// // 231 | 232 | // parseColor parses hex color 233 | func parseColor(c string) int64 { 234 | if strings.HasPrefix(c, "#") { 235 | c = strings.TrimLeft(c, "#") 236 | } 237 | 238 | // Shorthand hex color 239 | if len(c) == 3 { 240 | c = strings.Repeat(string(c[0]), 2) + 241 | strings.Repeat(string(c[1]), 2) + 242 | strings.Repeat(string(c[2]), 2) 243 | } 244 | 245 | i, _ := strconv.ParseInt(c, 16, 32) 246 | 247 | return i 248 | } 249 | 250 | // formatColor formats color 251 | func formatColor(c int64) string { 252 | k := fmt.Sprintf("%06x", c) 253 | 254 | if k[0] == k[1] && k[2] == k[3] && k[4] == k[5] { 255 | k = k[0:1] + k[2:3] + k[4:5] 256 | } 257 | 258 | return "#" + k 259 | } 260 | 261 | // formatFloat formats float values 262 | func formatFloat(v float64) string { 263 | return strconv.FormatFloat(v, 'f', 0, 64) 264 | } 265 | 266 | // getMessageColors returns message text and shadow colors based on color of badge 267 | func getMessageColors(c int64) (string, string) { 268 | if c == 0 || calcLuminance(c) < 0.65 { 269 | return "#fff", "#010101" 270 | } 271 | 272 | return "#333", "#ccc" 273 | } 274 | 275 | // calcLuminance calculates relative luminance 276 | func calcLuminance(color int64) float64 { 277 | r := calcLumColor(float64(color>>16&0xFF) / 255) 278 | g := calcLumColor(float64(color>>8&0xFF) / 255) 279 | b := calcLumColor(float64(color&0xFF) / 255) 280 | 281 | return 0.2126*r + 0.7152*g + 0.0722*b 282 | } 283 | 284 | // calcLumColor calculates luminance for one color 285 | func calcLumColor(c float64) float64 { 286 | if c <= 0.03928 { 287 | return c / 12.92 288 | } 289 | 290 | return math.Pow(((c + 0.055) / 1.055), 2.4) 291 | } 292 | -------------------------------------------------------------------------------- /badge_test.go: -------------------------------------------------------------------------------- 1 | package badge 2 | 3 | // ////////////////////////////////////////////////////////////////////////////////// // 4 | // // 5 | // Copyright (c) 2024 ESSENTIAL KAOS // 6 | // Apache License, Version 2.0 // 7 | // // 8 | // ////////////////////////////////////////////////////////////////////////////////// // 9 | 10 | import ( 11 | "fmt" 12 | "os" 13 | "testing" 14 | 15 | . "github.com/essentialkaos/check" 16 | ) 17 | 18 | // ////////////////////////////////////////////////////////////////////////////////// // 19 | 20 | func Test(t *testing.T) { TestingT(t) } 21 | 22 | type BadgeSuite struct{} 23 | 24 | // ////////////////////////////////////////////////////////////////////////////////// // 25 | 26 | type ErrReader struct{} 27 | 28 | func (e *ErrReader) Read(b []byte) (int, error) { 29 | return 0, fmt.Errorf("ERROR") 30 | } 31 | 32 | // ////////////////////////////////////////////////////////////////////////////////// // 33 | 34 | var _ = Suite(&BadgeSuite{}) 35 | 36 | // ////////////////////////////////////////////////////////////////////////////////// // 37 | func (s *BadgeSuite) SetUpTest(c *C) { 38 | fd, err := os.Open("Verdana.ttf") 39 | 40 | if err != nil { 41 | c.Fatal(err.Error()) 42 | } 43 | 44 | defer fd.Close() 45 | } 46 | 47 | func (s *BadgeSuite) TestConstructors(c *C) { 48 | fd, err := os.Open("Verdana.ttf") 49 | 50 | if err != nil { 51 | c.Fatal(err.Error()) 52 | } 53 | 54 | defer fd.Close() 55 | 56 | _, err = NewGenerator("Verdana.ttf", 11) 57 | c.Assert(err, IsNil) 58 | 59 | _, err = NewGeneratorFromReader(fd, 11) 60 | c.Assert(err, IsNil) 61 | } 62 | 63 | func (s *BadgeSuite) TestErrors(c *C) { 64 | _, err := NewGenerator("unknown.ttf", 0) 65 | c.Assert(err, NotNil) 66 | 67 | _, err = NewGenerator("badge.go", 0) 68 | c.Assert(err, NotNil) 69 | 70 | errReader := &ErrReader{} 71 | 72 | _, err = NewGeneratorFromReader(errReader, 0) 73 | c.Assert(err, NotNil) 74 | 75 | _, err = NewGeneratorFromBytes(nil, 0) 76 | c.Assert(err, NotNil) 77 | } 78 | 79 | func (s *BadgeSuite) TestPlastic(c *C) { 80 | srcBadge, err := os.ReadFile("testdata/plastic.svg") 81 | 82 | if err != nil { 83 | c.Fatal(err.Error()) 84 | } 85 | 86 | gen, err := NewGenerator("Verdana.ttf", 11) 87 | c.Assert(err, IsNil) 88 | 89 | ourBadge := gen.GeneratePlastic("label", "message", COLOR_RED) 90 | 91 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 92 | } 93 | 94 | func (s *BadgeSuite) TestFlat(c *C) { 95 | srcBadge, err := os.ReadFile("testdata/flat.svg") 96 | 97 | if err != nil { 98 | c.Fatal(err.Error()) 99 | } 100 | 101 | gen, err := NewGenerator("Verdana.ttf", 11) 102 | c.Assert(err, IsNil) 103 | 104 | ourBadge := gen.GenerateFlat("label", "message", COLOR_RED) 105 | 106 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 107 | } 108 | 109 | func (s *BadgeSuite) TestFlatSquare(c *C) { 110 | srcBadge, err := os.ReadFile("testdata/square.svg") 111 | 112 | if err != nil { 113 | c.Fatal(err.Error()) 114 | } 115 | 116 | gen, err := NewGenerator("Verdana.ttf", 11) 117 | c.Assert(err, IsNil) 118 | 119 | ourBadge := gen.GenerateFlatSquare("label", "message", COLOR_RED) 120 | 121 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 122 | } 123 | 124 | func (s *BadgeSuite) TestPlasticSimple(c *C) { 125 | srcBadge, err := os.ReadFile("testdata/plastic_simple.svg") 126 | 127 | if err != nil { 128 | c.Fatal(err.Error()) 129 | } 130 | 131 | gen, err := NewGenerator("Verdana.ttf", 11) 132 | c.Assert(err, IsNil) 133 | 134 | ourBadge := gen.GeneratePlastic("", "message", COLOR_RED) 135 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 136 | 137 | ourBadge = gen.GeneratePlasticSimple("message", COLOR_RED) 138 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 139 | } 140 | 141 | func (s *BadgeSuite) TestFlatSimple(c *C) { 142 | srcBadge, err := os.ReadFile("testdata/flat_simple.svg") 143 | 144 | if err != nil { 145 | c.Fatal(err.Error()) 146 | } 147 | 148 | gen, err := NewGenerator("Verdana.ttf", 11) 149 | c.Assert(err, IsNil) 150 | 151 | ourBadge := gen.GenerateFlat("", "message", COLOR_RED) 152 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 153 | 154 | ourBadge = gen.GenerateFlatSimple("message", COLOR_RED) 155 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 156 | } 157 | 158 | func (s *BadgeSuite) TestFlatSquareSimple(c *C) { 159 | srcBadge, err := os.ReadFile("testdata/square_simple.svg") 160 | 161 | if err != nil { 162 | c.Fatal(err.Error()) 163 | } 164 | 165 | gen, err := NewGenerator("Verdana.ttf", 11) 166 | c.Assert(err, IsNil) 167 | 168 | ourBadge := gen.GenerateFlatSquare("", "message", COLOR_RED) 169 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 170 | 171 | ourBadge = gen.GenerateFlatSquareSimple("message", COLOR_RED) 172 | c.Assert(string(ourBadge), Equals, string(srcBadge)) 173 | } 174 | 175 | func (s *BadgeSuite) TestBlackAndWhite(c *C) { 176 | bb, err := os.ReadFile("testdata/black.svg") 177 | 178 | if err != nil { 179 | c.Fatal(err.Error()) 180 | } 181 | 182 | wb, err := os.ReadFile("testdata/white.svg") 183 | 184 | if err != nil { 185 | c.Fatal(err.Error()) 186 | } 187 | 188 | gen, err := NewGenerator("Verdana.ttf", 11) 189 | c.Assert(err, IsNil) 190 | 191 | ourBadge := gen.GenerateFlatSimple("message", "#FFFFFF") 192 | c.Assert(string(ourBadge), Equals, string(wb)) 193 | 194 | ourBadge = gen.GenerateFlatSimple("message", "#000000") 195 | c.Assert(string(ourBadge), Equals, string(bb)) 196 | } 197 | 198 | func (s *BadgeSuite) TestAux(c *C) { 199 | c.Assert(parseColor("000000"), Equals, int64(0x000000)) 200 | c.Assert(parseColor("#000000"), Equals, int64(0x000000)) 201 | c.Assert(parseColor("#4c1"), Equals, int64(0x44cc11)) 202 | 203 | c.Assert(formatColor(0x000000), Equals, "#000") 204 | c.Assert(formatColor(0xFCA1B4), Equals, "#fca1b4") 205 | 206 | c.Assert(calcLumColor(0.7), Equals, 0.4479884124418833) 207 | c.Assert(calcLumColor(0.01), Equals, 0.0007739938080495357) 208 | } 209 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/essentialkaos/go-badge 2 | 3 | go 1.23.6 4 | 5 | require ( 6 | github.com/essentialkaos/check v1.4.1 7 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 8 | golang.org/x/image v0.27.0 9 | ) 10 | 11 | require ( 12 | github.com/kr/pretty v0.3.1 // indirect 13 | github.com/kr/text v0.2.0 // indirect 14 | github.com/rogpeppe/go-internal v1.13.1 // indirect 15 | ) 16 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 2 | github.com/essentialkaos/check v1.4.1 h1:SuxXzrbokPGTPWxGRnzy0hXvtb44mtVrdNxgPa1s4c8= 3 | github.com/essentialkaos/check v1.4.1/go.mod h1:xQOYwFvnxfVZyt5Qvjoa1SxcRqu5VyP77pgALr3iu+M= 4 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= 5 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= 6 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 7 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 8 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 9 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 10 | github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= 11 | github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= 12 | github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= 13 | github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= 14 | golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w= 15 | golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g= 16 | -------------------------------------------------------------------------------- /testdata/black.svg: -------------------------------------------------------------------------------- 1 | messagemessage -------------------------------------------------------------------------------- /testdata/flat.svg: -------------------------------------------------------------------------------- 1 | label: messagelabelmessage -------------------------------------------------------------------------------- /testdata/flat_simple.svg: -------------------------------------------------------------------------------- 1 | messagemessage -------------------------------------------------------------------------------- /testdata/plastic.svg: -------------------------------------------------------------------------------- 1 | label: messagelabelmessage -------------------------------------------------------------------------------- /testdata/plastic_simple.svg: -------------------------------------------------------------------------------- 1 | TESTTESTmessage -------------------------------------------------------------------------------- /testdata/square.svg: -------------------------------------------------------------------------------- 1 | label: messagelabelmessage -------------------------------------------------------------------------------- /testdata/square_simple.svg: -------------------------------------------------------------------------------- 1 | messagemessage -------------------------------------------------------------------------------- /testdata/white.svg: -------------------------------------------------------------------------------- 1 | messagemessage --------------------------------------------------------------------------------