Golint cleanup from top level

This commit is contained in:
Harshavardhana 2015-03-05 21:09:16 -08:00
parent 540723d7ae
commit c00d1461b9
8 changed files with 56 additions and 31 deletions

View File

@ -54,7 +54,8 @@ Building Libraries
- Run `make save` from top-level directory (or `godep restore && godep save ./...`). - Run `make save` from top-level directory (or `godep restore && godep save ./...`).
* When you're ready to create a pull request, be sure to: * When you're ready to create a pull request, be sure to:
- Have test cases for the new code. If you have questions about how to do it, please ask in your pull request. - Have test cases for the new code. If you have questions about how to do it, please ask in your pull request.
- Run `go fmt` - Run `go fmt
- Run `golint` (`go get github.com/golang/lint/golint`)
- Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request. - Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request.
- Make sure `go test -race ./...` and `go build` completes. - Make sure `go test -race ./...` and `go build` completes.
* Read [Effective Go](https://github.com/golang/go/wiki/CodeReviewComments) article from Golang project * Read [Effective Go](https://github.com/golang/go/wiki/CodeReviewComments) article from Golang project

20
main.go
View File

@ -27,14 +27,14 @@ import (
func getStorageType(input string) server.StorageType { func getStorageType(input string) server.StorageType {
switch { switch {
case input == "file": case input == "file":
return server.FileStorage return server.File
case input == "inmemory": case input == "inmemory":
return server.InMemoryStorage return server.InMemory
default: default:
{ {
log.Println("Unknown storage type:", input) log.Println("Unknown storage type:", input)
log.Println("Choosing default storage type as 'file'..") log.Println("Choosing default storage type as 'file'..")
return server.FileStorage return server.File
} }
} }
} }
@ -51,24 +51,24 @@ func runCmd(c *cli.Context) {
} }
tls := (certFile != "" && keyFile != "") tls := (certFile != "" && keyFile != "")
storageType := getStorageType(storageTypeStr) storageType := getStorageType(storageTypeStr)
var serverConfigs []server.ServerConfig var serverConfigs []server.Config
apiServerConfig := server.ServerConfig{ apiServerConfig := server.Config{
Domain: domain, Domain: domain,
Address: apiaddress, Address: apiaddress,
Tls: tls, TLS: tls,
CertFile: certFile, CertFile: certFile,
KeyFile: keyFile, KeyFile: keyFile,
ApiType: server.MinioApi{ APIType: server.MinioAPI{
StorageType: storageType, StorageType: storageType,
}, },
} }
webUIServerConfig := server.ServerConfig{ webUIServerConfig := server.Config{
Domain: domain, Domain: domain,
Address: webaddress, Address: webaddress,
Tls: false, TLS: false,
CertFile: "", CertFile: "",
KeyFile: "", KeyFile: "",
ApiType: server.WebUIApi{ APIType: server.WebAPI{
Websocket: false, Websocket: false,
}, },
} }

View File

@ -34,10 +34,10 @@ type Config struct {
type Server struct{} type Server struct{}
// Start http server // Start http server
func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *Server) { func Start(handler http.Handler, config Config) (chan<- string, <-chan error, *Server) {
ctrlChannel := make(chan string) ctrlChannel := make(chan string)
errorChannel := make(chan error) errorChannel := make(chan error)
server := HttpServer{} server := Server{}
go start(ctrlChannel, errorChannel, handler, config, &server) go start(ctrlChannel, errorChannel, handler, config, &server)
return ctrlChannel, errorChannel, &server return ctrlChannel, errorChannel, &server
} }

View File

@ -45,8 +45,8 @@ type MinioAPI struct {
StorageType StorageType StorageType StorageType
} }
// WebUIApi - webui related // WebAPI - webui related
type WebUIApi struct { type WebAPI struct {
Websocket bool // TODO Websocket bool // TODO
} }
@ -66,15 +66,15 @@ func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans [
var statusChan <-chan error var statusChan <-chan error
for _, config := range configs { for _, config := range configs {
switch k := config.ApiType.(type) { switch k := config.APIType.(type) {
case MinioApi: case MinioAPI:
{ {
// configure web server // configure web server
var storage mstorage.Storage var storage mstorage.Storage
var httpConfig = httpserver.Config{} var httpConfig = httpserver.Config{}
httpConfig.Address = config.Address httpConfig.Address = config.Address
httpConfig.Websocket = false httpConfig.Websocket = false
httpConfig.TLS = config.Tls httpConfig.TLS = config.TLS
if config.CertFile != "" { if config.CertFile != "" {
httpConfig.CertFile = config.CertFile httpConfig.CertFile = config.CertFile
@ -85,22 +85,22 @@ func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans [
ctrlChans, statusChans, storage = getStorageChannels(k.StorageType) ctrlChans, statusChans, storage = getStorageChannels(k.StorageType)
// start minio api in a web server, pass storage driver into it // start minio api in a web server, pass storage driver into it
ctrlChan, statusChan, _ = httpserver.Start(minioapi.HttpHandler(config.Domain, storage), httpConfig) ctrlChan, statusChan, _ = httpserver.Start(minioapi.HTTPHandler(config.Domain, storage), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan) ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan) statusChans = append(statusChans, statusChan)
} }
case WebUIApi: case WebAPI:
{ {
var httpConfig = httpserver.Config{} var httpConfig = httpserver.Config{}
httpConfig.Address = config.Address httpConfig.Address = config.Address
httpConfig.TLS = config.Tls httpConfig.TLS = config.TLS
httpConfig.CertFile = config.CertFile httpConfig.CertFile = config.CertFile
httpConfig.KeyFile = config.KeyFile httpConfig.KeyFile = config.KeyFile
httpConfig.Websocket = k.Websocket httpConfig.Websocket = k.Websocket
ctrlChan, statusChan, _ = httpserver.Start(webuiapi.HttpHandler(), httpConfig) ctrlChan, statusChan, _ = httpserver.Start(webuiapi.HTTPHandler(), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan) ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan) statusChans = append(statusChans, statusChan)

View File

@ -24,8 +24,10 @@ import (
"io" "io"
) )
// Metadata map
type Metadata map[string]string type Metadata map[string]string
// DataHeader struct
type DataHeader struct { type DataHeader struct {
Key string Key string
Part uint8 Part uint8
@ -33,13 +35,16 @@ type DataHeader struct {
EncoderParams EncoderParams EncoderParams EncoderParams
} }
// EncoderTechnique type
type EncoderTechnique int type EncoderTechnique int
// EncoderTechniques
const ( const (
Vandermonde EncoderTechnique = iota Vandermonde EncoderTechnique = iota
Cauchy Cauchy
) )
// EncoderParams struct
type EncoderParams struct { type EncoderParams struct {
Length uint32 Length uint32
K uint8 K uint8
@ -47,7 +52,7 @@ type EncoderParams struct {
Technique EncoderTechnique Technique EncoderTechnique
} }
// populate new header // NewHeader populate new header
func NewHeader(key string, part uint8, metadata Metadata, encoderParams EncoderParams) DataHeader { func NewHeader(key string, part uint8, metadata Metadata, encoderParams EncoderParams) DataHeader {
header := DataHeader{} header := DataHeader{}
header.Key = key header.Key = key
@ -62,7 +67,7 @@ func NewHeader(key string, part uint8, metadata Metadata, encoderParams EncoderP
return header return header
} }
// validate populated header // ValidateHeader validate populated header
func ValidateHeader(header DataHeader) bool { func ValidateHeader(header DataHeader) bool {
if header.Key == "" || header.Part < 0 || len(header.Metadata) < 2 { if header.Key == "" || header.Part < 0 || len(header.Metadata) < 2 {
return false return false
@ -75,7 +80,7 @@ func ValidateHeader(header DataHeader) bool {
return true return true
} }
// Write data, returns error upon any failure // WriteData write data, returns error upon any failure
func WriteData(target io.Writer, header DataHeader, data io.Reader) error { func WriteData(target io.Writer, header DataHeader, data io.Reader) error {
if !ValidateHeader(header) { if !ValidateHeader(header) {
return fmt.Errorf("Invalid header") return fmt.Errorf("Invalid header")

View File

@ -44,30 +44,49 @@ import (
*/ */
// Magic list
var ( var (
MagicMINI = binary.LittleEndian.Uint32([]byte{'M', 'I', 'N', 'I'}) MagicMINI = binary.LittleEndian.Uint32([]byte{'M', 'I', 'N', 'I'})
MagicDATA = binary.LittleEndian.Uint32([]byte{'D', 'A', 'T', 'A'}) MagicDATA = binary.LittleEndian.Uint32([]byte{'D', 'A', 'T', 'A'})
MagicINIM = binary.LittleEndian.Uint32([]byte{'I', 'N', 'I', 'M'}) MagicINIM = binary.LittleEndian.Uint32([]byte{'I', 'N', 'I', 'M'})
) )
// DonutFrameHeader -
// --------------
// BlockStart uint32
// VersionMajor uint32
// Reserved uint64
// DataLen uint64
// --------------
type DonutFrameHeader struct { type DonutFrameHeader struct {
MagicMINI uint32 MagicMINI uint32
Version uint32 Version uint32
Reserved uint64 Reserved uint64
DataLength uint64 DataLength uint64
} }
// Crc32c checksum
type Crc32c uint32 type Crc32c uint32
// Sha512 checksum
type Sha512 [sha512.Size]byte type Sha512 [sha512.Size]byte
// DonutFrameFooter -
// --------------
// DataSha512 [64]byte
// BlockLen uint64
// BlockEnd uint32
// --------------
type DonutFrameFooter struct { type DonutFrameFooter struct {
DataSha512 Sha512 DataSha512 Sha512
OffsetToMINI uint64 OffsetToMINI uint64
MagicINIM uint32 MagicINIM uint32
} }
// Data buffer
type Data bytes.Buffer type Data bytes.Buffer
// Write Donut format to input io.Writer, returns error upon any failure // WriteFrame - write donut format to input io.Writer, returns error upon any failure
func WriteFrame(target io.Writer, reader io.Reader, length uint64) error { func WriteFrame(target io.Writer, reader io.Reader, length uint64) error {
// write header // write header
header := DonutFrameHeader{ header := DonutFrameHeader{

View File

@ -46,8 +46,8 @@ func (s *MySuite) TestConfig(c *C) {
} }
conf.configLock = new(sync.RWMutex) conf.configLock = new(sync.RWMutex)
accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MINIO_ACCESS_ID) accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
secretkey, _ := keys.GenerateRandomBase64(keys.MINIO_SECRET_ID) secretkey, _ := keys.GenerateRandomBase64(keys.MinioSecretID)
user := User{ user := User{
Name: "gnubot", Name: "gnubot",
@ -62,8 +62,8 @@ func (s *MySuite) TestConfig(c *C) {
err = conf.ReadConfig() err = conf.ReadConfig()
c.Assert(err, IsNil) c.Assert(err, IsNil)
accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MINIO_ACCESS_ID) accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
secretkey, _ = keys.GenerateRandomBase64(keys.MINIO_SECRET_ID) secretkey, _ = keys.GenerateRandomBase64(keys.MinioSecretID)
user = User{ user = User{
Name: "minio", Name: "minio",
AccessKey: string(accesskey), AccessKey: string(accesskey),

View File

@ -31,7 +31,7 @@ var _ = Suite(&MySuite{})
func (s *MySuite) Testing(c *C) { func (s *MySuite) Testing(c *C) {
certObj := Certificates{} certObj := Certificates{}
params := X509Params{ params := Params{
Hostname: "example.com", Hostname: "example.com",
IsCA: false, IsCA: false,
EcdsaCurve: "P224", EcdsaCurve: "P224",