mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Add comments
This commit is contained in:
parent
721ec9ef5a
commit
137584d658
@ -118,15 +118,19 @@ func doPackage(fs *token.FileSet, pkg *ast.Package) {
|
||||
}
|
||||
}
|
||||
case *ast.FuncDecl:
|
||||
// Skip if function is 'main'
|
||||
// if function is 'main', never check
|
||||
if n.Name.Name == "main" {
|
||||
continue
|
||||
}
|
||||
// Skip non-exported functions
|
||||
// Do not be strict on non-exported functions
|
||||
if !ast.IsExported(n.Name.Name) {
|
||||
continue
|
||||
}
|
||||
// Check if comments are missing from exported functions
|
||||
// Do not be strict for field list functions
|
||||
// if n.Recv != nil {
|
||||
// continue
|
||||
//}
|
||||
// Be strict for global functions
|
||||
_, ok := cmap[n]
|
||||
if ok == false {
|
||||
p.missingcomments[n.Name.Name] = n
|
||||
|
@ -58,6 +58,15 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error, s *storage) {
|
||||
close(errorChannel)
|
||||
}
|
||||
|
||||
func appendUniq(slice []string, i string) []string {
|
||||
for _, ele := range slice {
|
||||
if ele == i {
|
||||
return slice
|
||||
}
|
||||
}
|
||||
return append(slice, i)
|
||||
}
|
||||
|
||||
// Bucket Operations
|
||||
func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
|
||||
files, err := ioutil.ReadDir(storage.root)
|
||||
@ -379,7 +388,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
|
||||
}
|
||||
metadataList = append(metadataList, metadata)
|
||||
case delimited != "":
|
||||
resources.CommonPrefixes = helpers.AppendUniqStr(resources.CommonPrefixes, delimited)
|
||||
resources.CommonPrefixes = helpers.appendUniq(resources.CommonPrefixes, delimited)
|
||||
}
|
||||
case resources.Delimiter != "" && strings.HasPrefix(name, resources.Prefix):
|
||||
delimited := delimiter(name, resources.Delimiter)
|
||||
|
@ -47,6 +47,23 @@ type storedObject struct {
|
||||
data []byte
|
||||
}
|
||||
|
||||
// Start inmemory object server
|
||||
func Start() (chan<- string, <-chan error, *storage) {
|
||||
ctrlChannel := make(chan string)
|
||||
errorChannel := make(chan error)
|
||||
go start(ctrlChannel, errorChannel)
|
||||
return ctrlChannel, errorChannel, &storage{
|
||||
bucketdata: make(map[string]storedBucket),
|
||||
objectdata: make(map[string]storedObject),
|
||||
lock: new(sync.RWMutex),
|
||||
}
|
||||
}
|
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
||||
close(errorChannel)
|
||||
}
|
||||
|
||||
// GET object from memory buffer
|
||||
func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) {
|
||||
// TODO synchronize access
|
||||
// get object
|
||||
@ -60,14 +77,17 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
|
||||
}
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error {
|
||||
return mstorage.ApiNotImplemented{Api: "PutBucketPolicy"}
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) {
|
||||
return policy.BucketPolicy{}, mstorage.ApiNotImplemented{Api: "GetBucketPolicy"}
|
||||
}
|
||||
|
||||
// PUT object to memory buffer
|
||||
func (storage *storage) StoreObject(bucket, key, contentType string, data io.Reader) error {
|
||||
storage.lock.Lock()
|
||||
defer storage.lock.Unlock()
|
||||
@ -108,6 +128,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create Bucket in memory
|
||||
func (storage *storage) StoreBucket(bucketName string) error {
|
||||
storage.lock.Lock()
|
||||
defer storage.lock.Unlock()
|
||||
@ -128,11 +149,11 @@ func (storage *storage) StoreBucket(bucketName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// List objects in memory
|
||||
func (storage *storage) ListObjects(bucket string, resources mstorage.BucketResourcesMetadata) ([]mstorage.ObjectMetadata, mstorage.BucketResourcesMetadata, error) {
|
||||
if _, ok := storage.bucketdata[bucket]; ok == false {
|
||||
return []mstorage.ObjectMetadata{}, mstorage.BucketResourcesMetadata{IsTruncated: false}, mstorage.BucketNotFound{Bucket: bucket}
|
||||
}
|
||||
// TODO prefix and count handling
|
||||
var results []mstorage.ObjectMetadata
|
||||
var keys []string
|
||||
for key := range storage.objectdata {
|
||||
@ -157,10 +178,16 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
|
||||
|
||||
type ByBucketName []mstorage.BucketMetadata
|
||||
|
||||
func (b ByBucketName) Len() int { return len(b) }
|
||||
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
// Len of bucket name
|
||||
func (b ByBucketName) Len() int { return len(b) }
|
||||
|
||||
// Swap bucket i, j
|
||||
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
|
||||
// Less
|
||||
func (b ByBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name }
|
||||
|
||||
// List buckets
|
||||
func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
|
||||
var results []mstorage.BucketMetadata
|
||||
for _, bucket := range storage.bucketdata {
|
||||
@ -170,21 +197,7 @@ func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func Start() (chan<- string, <-chan error, *storage) {
|
||||
ctrlChannel := make(chan string)
|
||||
errorChannel := make(chan error)
|
||||
go start(ctrlChannel, errorChannel)
|
||||
return ctrlChannel, errorChannel, &storage{
|
||||
bucketdata: make(map[string]storedBucket),
|
||||
objectdata: make(map[string]storedObject),
|
||||
lock: new(sync.RWMutex),
|
||||
}
|
||||
}
|
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
||||
close(errorChannel)
|
||||
}
|
||||
|
||||
// HEAD object
|
||||
func (storage *storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMetadata, error) {
|
||||
objectKey := bucket + ":" + key
|
||||
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/crypto/keys"
|
||||
"github.com/minio-io/minio/pkg/utils/helpers"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@ -35,7 +34,7 @@ func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
func (s *MySuite) TestConfig(c *C) {
|
||||
conf := Config{}
|
||||
conf.configPath, _ = helpers.MakeTempTestDir()
|
||||
conf.configPath, _ = ioutil.TempDir("/tmp", "minio-test-")
|
||||
defer os.RemoveAll(conf.configPath)
|
||||
conf.configFile = path.Join(conf.configPath, "config.json")
|
||||
if _, err := os.Stat(conf.configFile); os.IsNotExist(err) {
|
||||
|
@ -21,14 +21,17 @@ package cpu
|
||||
// int has_avx2 (void);
|
||||
import "C"
|
||||
|
||||
// CPUID instruction verification wrapper for SSE41 extensions
|
||||
func HasSSE41() bool {
|
||||
return int(C.has_sse41()) == 1
|
||||
}
|
||||
|
||||
// CPUID instruction verification wrapper for AVX extensions
|
||||
func HasAVX() bool {
|
||||
return int(C.has_avx()) == 1
|
||||
}
|
||||
|
||||
// CPUID instruction verification wrapper for AVX2 extensions
|
||||
func HasAVX2() bool {
|
||||
return int(C.has_avx2()) == 1
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ func block(dig *digest, p []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
// Reset digest to its default value
|
||||
func (d *digest) Reset() {
|
||||
d.h[0] = init0
|
||||
d.h[1] = init1
|
||||
@ -75,12 +76,13 @@ func New() hash.Hash {
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *digest) Size() int {
|
||||
return Size
|
||||
}
|
||||
// Return output array byte size
|
||||
func (d *digest) Size() int { return Size }
|
||||
|
||||
// Return blockSize
|
||||
func (d *digest) BlockSize() int { return BlockSize }
|
||||
|
||||
// Write blocks
|
||||
func (d *digest) Write(p []byte) (nn int, err error) {
|
||||
nn = len(p)
|
||||
d.len += uint64(nn)
|
||||
@ -104,6 +106,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Calculate sha512
|
||||
func (d0 *digest) Sum(in []byte) []byte {
|
||||
// Make a copy of d0 so that caller can keep writing and summing.
|
||||
d := new(digest)
|
||||
@ -112,6 +115,7 @@ func (d0 *digest) Sum(in []byte) []byte {
|
||||
return append(in, hash[:]...)
|
||||
}
|
||||
|
||||
// internal checksum calculation, returns [Size]byte
|
||||
func (d *digest) checkSum() [Size]byte {
|
||||
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
|
||||
len := d.len
|
||||
@ -153,6 +157,7 @@ func (d *digest) checkSum() [Size]byte {
|
||||
|
||||
// Convenience functions
|
||||
|
||||
// Single caller function returns [Size]byte
|
||||
func Sum512(data []byte) [Size]byte {
|
||||
var d digest
|
||||
d.Reset()
|
||||
@ -160,6 +165,7 @@ func Sum512(data []byte) [Size]byte {
|
||||
return d.checkSum()
|
||||
}
|
||||
|
||||
// Takes in io.Reader, low memory footprint checksum
|
||||
func Sum(reader io.Reader) ([]byte, error) {
|
||||
h := New()
|
||||
var err error
|
||||
@ -176,6 +182,7 @@ func Sum(reader io.Reader) ([]byte, error) {
|
||||
return h.Sum(nil), nil
|
||||
}
|
||||
|
||||
// Similar to 'Sum()' but returns a [Size]byte
|
||||
func SumStream(reader io.Reader) ([Size]byte, error) {
|
||||
var returnValue [Size]byte
|
||||
sumSlice, err := Sum(reader)
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
sha512intel "github.com/minio-io/minio/pkg/utils/crypto/sha512"
|
||||
)
|
||||
|
||||
// Intels processor accelerated sha512 implementation
|
||||
func SumIntel(reader io.Reader) ([]byte, error) {
|
||||
h := sha512intel.New()
|
||||
var err error
|
||||
@ -45,6 +46,7 @@ func SumIntel(reader io.Reader) ([]byte, error) {
|
||||
return h.Sum(nil), nil
|
||||
}
|
||||
|
||||
// Golang default implementation
|
||||
func Sum(reader io.Reader) ([]byte, error) {
|
||||
k := sha512.New()
|
||||
var err error
|
||||
|
@ -72,6 +72,7 @@ func pemBlockForKey(priv interface{}) *pem.Block {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate certificates using custom parameters
|
||||
func (tls *Certificates) GenerateCertificates(params X509Params) error {
|
||||
var rsaBits int = 2048
|
||||
var priv interface{}
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* 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 helpers
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Create a new temp directory
|
||||
func MakeTempTestDir() (string, error) {
|
||||
return ioutil.TempDir("/tmp", "minio-test-")
|
||||
}
|
||||
|
||||
// Camelcase input string
|
||||
func FirstUpper(str string) string {
|
||||
return strings.ToUpper(str[0:1]) + str[1:]
|
||||
}
|
||||
|
||||
func AppendUniqInt(slice []int, i int) []int {
|
||||
for _, ele := range slice {
|
||||
if ele == i {
|
||||
return slice
|
||||
}
|
||||
}
|
||||
return append(slice, i)
|
||||
}
|
||||
|
||||
func AppendUniqStr(slice []string, i string) []string {
|
||||
for _, ele := range slice {
|
||||
if ele == i {
|
||||
return slice
|
||||
}
|
||||
}
|
||||
return append(slice, i)
|
||||
}
|
@ -13,6 +13,7 @@ type Date struct {
|
||||
Day byte
|
||||
}
|
||||
|
||||
// Date to string output in yyyy-mm-dd format
|
||||
func (d Date) String() string {
|
||||
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user