2022-12-02 02:08:48 +03:00
|
|
|
// Copyright 2021 OpenSSF Scorecard Authors
|
2021-06-27 19:04:00 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package data
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
2021-10-29 19:07:46 +03:00
|
|
|
// CSVStrings is []string with support for CSV formatting.
|
|
|
|
type CSVStrings []string
|
2021-06-27 19:04:00 +03:00
|
|
|
|
2021-10-29 19:07:46 +03:00
|
|
|
// MarshalCSV implements []string -> []byte serialization.
|
|
|
|
func (s CSVStrings) MarshalCSV() ([]byte, error) {
|
2021-06-27 19:04:00 +03:00
|
|
|
return []byte(strings.Join(s, ",")), nil
|
|
|
|
}
|
|
|
|
|
2024-01-27 02:08:26 +03:00
|
|
|
// UnmarshalCSV implements []byte -> []string de-serialization.
|
2021-10-29 19:07:46 +03:00
|
|
|
func (s *CSVStrings) UnmarshalCSV(input []byte) error {
|
2022-01-12 23:34:16 +03:00
|
|
|
if len(input) == 0 {
|
2021-06-27 19:04:00 +03:00
|
|
|
*s = nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
*s = strings.Split(string(input), ",")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-30 03:01:25 +03:00
|
|
|
// ToString converts CSVStrings -> []string.
|
|
|
|
func (s CSVStrings) ToString() []string {
|
|
|
|
var ret []string
|
|
|
|
for _, i := range s {
|
|
|
|
ret = append(ret, i)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-10-29 19:07:46 +03:00
|
|
|
// RepoFormat is used to read input repos.
|
|
|
|
type RepoFormat struct {
|
2021-06-27 19:04:00 +03:00
|
|
|
Repo string `csv:"repo"`
|
2021-10-29 19:07:46 +03:00
|
|
|
Metadata CSVStrings `csv:"metadata"`
|
2021-06-27 19:04:00 +03:00
|
|
|
}
|