func getAmazonLinux1or2(osVersion string) string {
	ss := strings.Fields(osVersion)
	if ss[0] == "2" {
		return "2"
	}
	return "1"
}
getAmazonLinux2 returns AmazonLinux1 or 2
package db
import (
	"fmt"
	"strings"
	"time"
	c "github.com/vulsio/goval-dictionary/config"
	"github.com/vulsio/goval-dictionary/models"
	"golang.org/x/xerrors"
)
type DB interface {
	Name() string
	OpenDB(string, string, bool, Option) (bool, error)
	CloseDB() error
	MigrateDB() error
	IsGovalDictModelV1() (bool, error)
	GetFetchMeta() (*models.FetchMeta, error)
	UpsertFetchMeta(*models.FetchMeta) error
	GetByPackName(family string, osVer string, packName string, arch string) ([]models.Definition, error)
	GetByCveID(family string, osVer string, cveID string, arch string) ([]models.Definition, error)
	InsertOval(*models.Root) error
	CountDefs(string, string) (int, error)
	GetLastModified(string, string) (time.Time, error)
}
type Option struct {
	RedisTimeout time.Duration
}
func NewDB(dbType, dbPath string, debugSQL bool, option Option) (driver DB, locked bool, err error) {
	if driver, err = newDB(dbType); err != nil {
		return driver, false, xerrors.Errorf("Failed to new db. err: %w", err)
	}
	if locked, err := driver.OpenDB(dbType, dbPath, debugSQL, option); err != nil {
		if locked {
			return nil, true, err
		}
		return nil, false, err
	}
	isV1, err := driver.IsGovalDictModelV1()
	if err != nil {
		return nil, false, xerrors.Errorf("Failed to IsGovalDictModelV1. err: %w", err)
	}
	if isV1 {
		return nil, false, xerrors.New("Failed to NewDB. Since SchemaVersion is incompatible, delete Database and fetch again.")
	}
	if err := driver.MigrateDB(); err != nil {
		return driver, false, xerrors.Errorf("Failed to migrate db. err: %w", err)
	}
	return driver, false, nil
}
func newDB(dbType string) (DB, error) {
	switch dbType {
	case dialectSqlite3, dialectMysql, dialectPostgreSQL:
		return &RDBDriver{name: dbType}, nil
	case dialectRedis:
		return &RedisDriver{name: dbType}, nil
	}
	return nil, fmt.Errorf("Invalid database dialect. dbType: %s", dbType)
}
func formatFamilyAndOSVer(family, osVer string) (string, string, error) {
	switch family {
	case c.Debian:
		osVer = major(osVer)
	case c.Ubuntu:
		osVer = major(osVer)
	case c.Raspbian:
		family = c.Debian
		osVer = major(osVer)
	case c.RedHat:
		osVer = major(osVer)
	case c.CentOS:
		family = c.RedHat
		osVer = major(osVer)
	case c.Oracle:
		osVer = major(osVer)
	case c.Amazon:
		osVer = getAmazonLinux1or2(osVer)
	case c.Alpine:
		osVer = majorDotMinor(osVer)
	default:
		if !strings.Contains(family, "suse") {
			return "", "", fmt.Errorf("Failed to detect family. err: unknown os family(%s)", family)
		}
	}
	return family, osVer, nil
}
func major(osVer string) (majorVersion string) {
	return strings.Split(osVer, ".")[0]
}
func majorDotMinor(osVer string) (majorMinorVersion string) {
	ss := strings.Split(osVer, ".")
	if len(ss) < 3 {
		return osVer
	}
	return strings.Join(ss[:2], ".")
}