-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Schmidt
committed
May 21, 2024
1 parent
b283db6
commit 4ef27d9
Showing
13 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
- name: Setup-go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.21 | ||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.58 | ||
args: --timeout=5m --out-format=colored-line-number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./docker/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
|
||
linters-settings: | ||
goconst: | ||
min-len: 2 | ||
min-occurrences: 3 | ||
gocritic: | ||
enabled-tags: | ||
- diagnostic | ||
- experimental | ||
- opinionated | ||
- performance | ||
- style | ||
govet: | ||
check-shadowing: true | ||
enable: | ||
- fieldalignment | ||
nolintlint: | ||
require-explanation: true | ||
require-specific: true | ||
depguard: | ||
rules: | ||
Main: | ||
allow: | ||
- $gostd | ||
- github.com/aerospike/aerospike-proximus-client-go/protos | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
# - unused # intentionally commented to avoid unused func warning as this repo is library | ||
- depguard | ||
- dogsled | ||
- dupl | ||
- errcheck | ||
- exportloopref | ||
- exhaustive | ||
- goconst | ||
- gocritic | ||
- gofmt | ||
- goimports | ||
- gocyclo | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- misspell | ||
- nolintlint | ||
- nakedret | ||
- prealloc # pre-allocate slices with define size if the slice size is known in advance | ||
- predeclared | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
- thelper | ||
- tparallel | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- whitespace | ||
- lll | ||
- wsl # While space linter | ||
|
||
run: | ||
issues-exit-code: 1 | ||
go: '1.21' | ||
# skip-dirs: | ||
# - sample | ||
# skip-files: | ||
# - sample | ||
|
||
# issues: | ||
# exclude-rules: | ||
# - path: info/as_parser_test\.go | ||
# linters: | ||
# - lll # Test code is allowed to have long lines | ||
# - path: asconfig/generate_test\.go | ||
# linters: | ||
# - dupl # Test code is allowed to have duplicate code | ||
# - path: asconfig/asconfig_test\.go | ||
# linters: | ||
# - dupl # Test code is allowed to have duplicate code | ||
# - path: '(.+)test\.go' | ||
# linters: | ||
# - govet # Test code field alignment for sake of space is not a concern | ||
# - linters: | ||
# - lll | ||
# source: "// " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// createCmd represents the create command | ||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("create called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(createCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// createCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"net" | ||
|
||
avs "github.com/aerospike/aerospike-proximus-client-go" | ||
"github.com/aerospike/aerospike-proximus-client-go/protos" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// createIndexCmd represents the createIndex command | ||
var createIndexCmd = &cobra.Command{ | ||
Use: "index", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
host := viper.GetString("host") | ||
port := viper.GetInt("port") | ||
hostPort := avs.NewHostPort(host, port, false) | ||
namespace := viper.GetString("namespace") | ||
sets := viper.GetStringSlice("sets") | ||
indexName := viper.GetString("index-name") | ||
vectorField := viper.GetString("vector-field") | ||
dimension := viper.GetUint32("dimension") | ||
// distanceMetric := viper.GetInt("distance-metric") | ||
indexMeta := viper.GetStringMapString("index-meta") | ||
|
||
logger.Debug("Parsed flags", slog.String("host", host), slog.Int("port", port), slog.String("namespace", namespace), slog.Any("sets", sets), slog.String("index-name", indexName), slog.String("vector-field", vectorField), slog.Uint64("dimension", uint64(dimension)), slog.Any("index-meta", indexMeta)) | ||
|
||
ctx := context.TODO() | ||
|
||
adminClient, err := avs.NewAdminClient(ctx, []*avs.HostPort{hostPort}, nil, false, logger) | ||
if err != nil { | ||
logger.Error("failed to create AVS client", slog.Any("error", err)) | ||
view.Printf("Failed to connect to AVS: %v", err) | ||
return | ||
} | ||
|
||
// TODO: parse cosine | ||
err = adminClient.IndexCreate(ctx, namespace, sets, indexName, vectorField, dimension, protos.VectorDistanceMetric_COSINE, nil, indexMeta) | ||
if err != nil { | ||
logger.Error("unable to create index", slog.Any("error", err)) | ||
view.Printf("Unable to create index: %v", err) | ||
return | ||
} | ||
|
||
view.Printf("Successfully created index %s.%s", namespace, indexName) | ||
}, | ||
} | ||
|
||
func init() { | ||
createCmd.AddCommand(createIndexCmd) | ||
createIndexCmd.PersistentFlags().IPP("host", "h", net.ParseIP("127.0.0.1"), "TODO") | ||
createIndexCmd.PersistentFlags().IntP("port", "p", 5000, "TODO") | ||
createIndexCmd.Flags().StringP("namespace", "n", "", "TODO") | ||
createIndexCmd.Flags().StringArrayP("sets", "s", nil, "TODO") | ||
createIndexCmd.Flags().StringP("index-name", "i", "", "TODO") | ||
createIndexCmd.Flags().StringP("vector-field", "v", "vector", "TODO") | ||
createIndexCmd.Flags().IntP("dimension", "d", 0, "TODO") | ||
createIndexCmd.Flags().Uint32P("distance-metric", "m", 0, "TODO") | ||
createIndexCmd.Flags().StringToStringP("index-meta", "e", nil, "TODO") | ||
// TODO hnsw metadata | ||
|
||
createIndexCmd.MarkFlagRequired("namespace") | ||
createIndexCmd.MarkFlagRequired("set") | ||
createIndexCmd.MarkFlagRequired("index-name") | ||
// createIndexCmd.MarkFlagRequired("vector-field") | ||
createIndexCmd.MarkFlagRequired("dimension") | ||
// createIndexCmd.MarkFlagRequired("distance-metric") | ||
viper.BindPFlags(createIndexCmd.PersistentFlags()) | ||
viper.BindPFlags(createIndexCmd.Flags()) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// createIndexCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// createIndexCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listCmd represents the list command | ||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("list called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(listCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// listCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listIndexCmd represents the listIndex command | ||
var listIndexCmd = &cobra.Command{ | ||
Use: "listIndex", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("listIndex called") | ||
}, | ||
} | ||
|
||
func init() { | ||
listCmd.AddCommand(listIndexCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// listIndexCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// listIndexCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
"os" | ||
|
||
common "github.com/aerospike/tools-common-go/flags" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var logger = slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{Level: slog.LevelError})) | ||
var view = NewView(os.Stdout) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "asvec", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.asvec.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
common.SetupRoot(rootCmd, "aerospike-vector-search", "0.0.0") | ||
viper.SetEnvPrefix("AVS") | ||
viper.AutomaticEnv() | ||
} |
Oops, something went wrong.