1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00
gocsaf/cmd/csaf_provider/main.go
Fadi Abbud 6fe6907c1d
Add --version option
* Add flag to display the version for each binary. It is based on `git describe` but adds
  a number to the PATCH level if we are between annotated tags, so makes it semver.org
 compatible. Use the "-ldflags" method that also works with go 1.17.
* Use Makefile bash and sed magic to do PATCH level increase if needed.

Co-authored-by: Bernhard Reiter <bernhard@intevation.de>
2022-04-13 14:27:11 +02:00

48 lines
1,016 B
Go

// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2021 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2021 Intevation GmbH <https://intevation.de>
package main
import (
"fmt"
"log"
"net/http/cgi"
"github.com/csaf-poc/csaf_distribution/util"
"github.com/jessevdk/go-flags"
)
type options struct {
Version bool `long:"version" description:"Display version of the binary"`
}
func main() {
cfg, err := loadConfig()
if err != nil {
log.Fatalf("error: %v\n", err)
}
var opts options
parser := flags.NewParser(&opts, flags.Default)
parser.Parse()
if opts.Version {
fmt.Println(util.SemVersion)
return
}
c, err := newController(cfg)
if err != nil {
log.Fatalf("error: %v\n", err)
}
pim := newPathInfoMux()
c.bind(pim)
if err := cgi.Serve(pim); err != nil {
log.Fatalf("error: %v\n", err)
}
}