Skip to content
Snippets Groups Projects
Commit 1663f7fd authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

initial version

parent d5b5c67e
No related branches found
No related tags found
No related merge requests found
/coverage/
/bin/
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
\ No newline at end of file
image: golang:1.16-buster
cache:
paths:
- /apt-cache
- /go/src/github.com
- /go/src/golang.org
- /go/src/google.golang.org
- /go/src/gopkg.in
stages:
- test
- build
before_script:
- go get -u golang.org/x/lint/golint
lint_code:
stage: test
script:
- make lint
only:
- merge_requests
build:
stage: build
script:
- make build
except:
- merge_requests
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeProfile" value="profile:default" />
<option name="activeRegion" value="eu-west-1" />
<option name="recentlyUsedProfiles">
<list>
<option value="profile:default" />
</list>
</option>
<option name="recentlyUsedRegions">
<list>
<option value="eu-west-1" />
</list>
</option>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownEnhProjectSettings">
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imagePathType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="true" showSelectionInPreview="true" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.md.nav.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" correctedInvalidSettings="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ATXHEADERSPACE" value="true" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="INTELLIJ_DUMMY_IDENTIFIER" value="true" />
<option name="RELAXEDHRULES" value="true" />
<option name="STRIKETHROUGH" value="true" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
</PegdownExtensions>
<ParserOptions>
<option name="COMMONMARK_LISTS" value="true" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="PRODUCTION_SPEC_PARSER" value="true" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" addPageHeader="false" addAnchorLinks="true" anchorLinksWrapText="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" defaultUrlTitle="false" migratedPlantUml="false" migratedAnchorLinks="false" plantUmlConversion="0">
<GeneratorProvider>
<provider providerId="com.vladsch.md.nav.editor.text.html.generator" providerName="Unmodified HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
<fencedCodeConversions />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.md.nav.editor.text.html.css" providerName="No Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/barcode-creator.iml" filepath="$PROJECT_DIR$/barcode-creator.iml" />
<module fileurl="file://$PROJECT_DIR$/../../network/connection-checker/connection-checker.iml" filepath="$PROJECT_DIR$/../../network/connection-checker/connection-checker.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
LICENSE 0 → 100644
MIT License
Copyright (c) 2021 schukai GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Makefile 0 → 100644
PROJECT_NAME := "connection-checker"
PKG := "gitlab.schukai.com/oss/utilities/commerce/barcode-creator"
PKG_LIST := $(shell go list ${PKG}/... )
GO_FILES := $(shell find . -name '*.go')
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
GOGET=$(GOCMD) get
GOFMT=$(GOCMD) fmt
GODOC=$(GOCMD) fmt
GOLINT=golint
default: help
help: ## show this help
@echo 'usage: make [target] ...'
@echo ''
@echo 'targets:'
@egrep '^(.+)\:\ .*##\ (.+)' ${MAKEFILE_LIST} | sed 's/:.*##/#/' | column -t -c 2 -s '#'
clean: ## go clean
$(GOCLEAN)
clean-all: ## remove all generated artifacts and clean all build artifacts
$(GOCLEAN) -i ./...
lint: ## run go lint on the source files
$(GOLINT) -set_exit_status .
doc: ## generate godocs and start a local documentation webserver on port 8085
godoc -http=:8085 -index
fmt: ## format the go source files
$(GOFMT) .
all: ## clean, format and build
make clean-all
make fmt
make build
build:
mkdir -p bin
$(GOCMD) build -o bin/barcode-creator
install: build
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
go.mod 0 → 100644
module gitlab.schukai.com/oss/utilities/commerce/barcode-creator
go 1.16
require (
github.com/boombuler/barcode v1.0.1 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
)
main.go 0 → 100644
package main
import (
"errors"
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/code128"
"github.com/boombuler/barcode/ean"
"github.com/boombuler/barcode/pdf417"
"github.com/boombuler/barcode/qr"
"github.com/fatih/color"
"github.com/jessevdk/go-flags"
"image/png"
//"image/png"
"os"
)
const (
exitOK = 0 /* successful termination */
exitUsage = 64 /* command line usage error */
exitIOErr = 74 /* input/output error */
)
var parser *flags.Parser
func checkArgs(args []string) {
if len(args) != 1 || args[0] == "" {
printErrorAndExit(errors.New("the required `barcode' was not specified"), exitUsage)
}
}
func writeBarcode(barcode barcode.Barcode) {
file, err := os.Create(opts.Filename)
if err != nil {
printErrorAndExit(err, exitIOErr)
}
defer file.Close()
err = png.Encode(file, barcode)
if err != nil {
printErrorAndExit(err, exitIOErr)
}
}
type dimmension struct {
Width int `long:"width" short:"w" description:"Width"`
Height int `long:"height" short:"g" description:"Height"`
}
// **********EANCOMMAND*****************
type EanCommand struct {
dimmension
}
var eanCommand EanCommand
func (x *EanCommand) Execute(args []string) error {
checkArgs(args)
code, err := ean.Encode(args[0])
if err != nil {
printErrorAndExit(err, exitUsage)
}
writeBarcode(scaleBarcode(code, x.Width, x.Height))
return nil
}
// **********QRCOMMAND*****************
type QrCommand struct {
dimmension
}
var qrCommand QrCommand
func (x *QrCommand) Execute(args []string) error {
checkArgs(args)
code, err := qr.Encode(args[0], qr.M, qr.Auto)
if err != nil {
printErrorAndExit(err, exitUsage)
}
writeBarcode(scaleBarcode(code, x.Width, x.Height))
return nil
}
// **********CODE128COMMAND*****************
type Code128Command struct {
dimmension
}
var code128Command Code128Command
func (x *Code128Command) Execute(args []string) error {
checkArgs(args)
code, err := code128.Encode(args[0])
if err != nil {
printErrorAndExit(err, exitUsage)
}
writeBarcode(scaleBarcode(code, x.Width, x.Height))
return nil
}
// **********CODE128COMMAND*****************
type PDF417Command struct {
dimmension
SecurityLevel byte `long:"security-level" short:"s" description:"securityLevel should be between 0 and 8. The higher the number, the more additional error-correction codes are added."`
}
var pdf417Command PDF417Command
func (x *PDF417Command) Execute(args []string) error {
checkArgs(args)
code, err := pdf417.Encode(args[0], x.SecurityLevel)
if err != nil {
printErrorAndExit(err, exitUsage)
}
writeBarcode(scaleBarcode(code, x.Width, x.Height))
return nil
}
// ***************************
var opts struct {
Filename string `long:"filename" short:"f" description:"png filename" required:"true"`
}
func printUsageAndExit(exitcode int) {
parser.WriteHelp(os.Stdout)
fmt.Println()
os.Exit(exitcode)
}
func printErrorAndExit(err error, exitcode int) {
out := color.New(color.FgRed).Add(color.Underline)
fmt.Println()
if err != nil {
out.Println(err.Error())
fmt.Println()
}
printUsageAndExit(exitcode)
}
func scaleBarcode(code barcode.Barcode, width, height int) barcode.Barcode {
if width == 0 {
height = 24 * code.Bounds().Max.Y
}
if height == 0 {
height = 24 * code.Bounds().Max.Y
}
barcode, err := barcode.Scale(code, width, height)
if err != nil {
printErrorAndExit(err, exitUsage)
}
return barcode
}
func main() {
parser = flags.NewParser(&opts, flags.HelpFlag)
//parser.Usage = "command -filename= [options] code"
parser.ShortDescription = "barcode output"
parser.LongDescription = "different barcodes can be created and saved as png."
parser.AddCommand("ean",
"EAN code",
"the ean command creates a png with an ean barcode.",
&eanCommand)
parser.AddCommand("qr",
"QR code",
"the qr command creates a png with an QR code.",
&qrCommand)
parser.AddCommand("code128",
"Code128 code",
"the code128 command creates a png with an code128 code.",
&code128Command)
parser.AddCommand("pdf417",
"PDF417 code",
"the pdf417 command creates a png with an pdf417 code.",
&pdf417Command)
_, err := parser.Parse()
if err != nil {
switch err.(type) {
case *flags.Error:
e := err.(*flags.Error)
if e.Type == flags.ErrHelp {
printUsageAndExit(exitOK)
} else {
printErrorAndExit(err, exitUsage)
}
}
}
os.Exit(exitOK)
}
test.png 0 → 100644
test.png

727 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment