Commit aedb0ea4 authored by Zhu Yong's avatar Zhu Yong
Browse files

Fix error message from golint, veriable naming, comments and etc.

parent e1f57f2d
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -4,11 +4,13 @@ import (
	kproto "github.com/yongzhy/kinetic-go/proto"
)

// BlockConnection still use NonBlockConnection to connect to kinetic device.
// For all API fucntions, it will only return after get response from kinetic drvice.
type BlockConnection struct {
	nbc *NonBlockConnection
}

// Helper function to establish block connection to device.
// NewBlockConnection is helper function to establish block connection to device.
func NewBlockConnection(op ClientOptions) (*BlockConnection, error) {
	nbc, err := NewNonBlockConnection(op)
	if err != nil {
@@ -36,7 +38,7 @@ func (conn *BlockConnection) get(key []byte, getCmd kproto.Command_MessageType)
	callback := &GetCallback{}
	h := NewResponseHandler(callback)

	var err error = nil
	var err error
	switch getCmd {
	case kproto.Command_GET:
		err = conn.nbc.Get(key, h)
@@ -161,7 +163,7 @@ func (conn *BlockConnection) pinop(pin []byte, op kproto.Command_PinOperation_Pi
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)

	var err error = nil
	var err error
	switch op {
	case kproto.Command_PinOperation_SECURE_ERASE_PINOP:
		err = conn.nbc.SecureErase(pin, h)
+6 −6
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ type Callback interface {
	Status() Status
}

// Generic Callback, can be used for all MessageType which doesn't require data from Kinetic drive.
// GenericCallback can be used for all MessageType which doesn't require data from Kinetic drive.
// And for MessageType that require data from drive, a new struct need to be defined GenericCallback
type GenericCallback struct {
	status Status
@@ -33,7 +33,7 @@ func (c *GenericCallback) Status() Status {
	return c.status
}

// Callback for Command_GET Message
// GetCallback is the Callback for Command_GET Message
type GetCallback struct {
	GenericCallback
	Entry Record // Entity information
@@ -51,7 +51,7 @@ func (c *GetCallback) Success(resp *kproto.Command, value []byte) {
	c.Entry.Value = value
}

// Callback for Command_GETKEYRANGE Message
// GetKeyRangeCallback is the Callback for Command_GETKEYRANGE Message
type GetKeyRangeCallback struct {
	GenericCallback
	Keys [][]byte // List of objects' keys within range, get from device
@@ -62,7 +62,7 @@ func (c *GetKeyRangeCallback) Success(resp *kproto.Command, value []byte) {
	c.Keys = resp.GetBody().GetRange().GetKeys()
}

// Callback for Command_GETVERSION Message
// GetVersionCallback is the Callback for Command_GETVERSION Message
type GetVersionCallback struct {
	GenericCallback
	Version []byte // Version of the object on device
@@ -73,7 +73,7 @@ func (c *GetVersionCallback) Success(resp *kproto.Command, value []byte) {
	c.Version = resp.GetBody().GetKeyValue().GetDbVersion()
}

// Callback for Command_PEER2PEERPUSH
// P2PPushCallback is the Callback for Command_PEER2PEERPUSH
type P2PPushCallback struct {
	GenericCallback
	Statuses []Status
@@ -88,7 +88,7 @@ func (c *P2PPushCallback) Success(resp *kproto.Command, value []byte) {
	}
}

// Callback for Command_GETLOG Message
// GetLogCallback is the Callback for Command_GETLOG Message
type GetLogCallback struct {
	GenericCallback
	Logs Log // Device log information
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ import (
)

var (
	blockConn    *BlockConnection    = nil
	nonblockConn *NonBlockConnection = nil
	blockConn    *BlockConnection
	nonblockConn *NonBlockConnection
)

var option = ClientOptions{
+42 −46
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ type ConfigurationLog struct {
	TlsPort                 int32                    // TLS service port
}

// Statistic information for each type of MessageType.
// StatisticsLog information for each type of MessageType.
// Count is total number of Type message processed.
// Bytes is the sum of the data that is in the data portion.
// This does not include the command description.
@@ -160,36 +160,36 @@ type DeviceLog struct {
type Log struct {
	Utilizations  []UtilizationLog  // List of utilization information of the drive
	Temperatures  []TemperatureLog  // List of tempeture inforamtion of the drive
	Capacity      CapacityLog      // Capacity information of the drive
	Configuration ConfigurationLog // Configuration information of the drive
	Capacity      *CapacityLog      // Capacity information of the drive
	Configuration *ConfigurationLog // Configuration information of the drive
	Statistics    []StatisticsLog   // List of statistic information from the drive
	Messages      []byte            // Kinetic log messages from the drive
	Limits        LimitsLog        // Limits information from the drive
	Device        DeviceLog
	Limits        *LimitsLog        // Limits information from the drive
	Device        *DeviceLog
}

func getUtilizationLogFromProto(getlog *kproto.Command_GetLog) []UtilizationLog {
func getUtilizationLogFromProto(getlog *kproto.Command_GetLog) (log []UtilizationLog) {
	log = nil
	utils := getlog.GetUtilizations()
	if utils != nil {
		ulog := make([]UtilizationLog, len(utils))
		log = make([]UtilizationLog, len(utils))
		for k, v := range utils {
			ulog[k] = UtilizationLog{
			log[k] = UtilizationLog{
				Name:  v.GetName(),
				Value: v.GetValue(),
			}
		}
		return ulog
	} else {
		return nil
	}
	return
}

func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) []TemperatureLog {
func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) (log []TemperatureLog) {
	log = nil
	temps := getlog.GetTemperatures()
	if temps != nil {
		templog := make([]TemperatureLog, len(temps))
		log = make([]TemperatureLog, len(temps))
		for k, v := range temps {
			templog[k] = TemperatureLog{
			log[k] = TemperatureLog{
				Name:    v.GetName(),
				Current: v.GetCurrent(),
				Minimum: v.GetMinimum(),
@@ -197,28 +197,27 @@ func getTemperatureLogFromProto(getlog *kproto.Command_GetLog) []TemperatureLog
				Target:  v.GetTarget(),
			}
		}
		return templog
	} else {
		return nil
	}
	return
}

func getCapacityLogFromProto(getlog *kproto.Command_GetLog) CapacityLog {
	var log CapacityLog
func getCapacityLogFromProto(getlog *kproto.Command_GetLog) (log *CapacityLog) {
	log = nil
	capacity := getlog.GetCapacity()
	if capacity != nil {
		log = CapacityLog{
		log = &CapacityLog{
			CapacityInBytes: capacity.GetNominalCapacityInBytes(),
			PortionFull:     capacity.GetPortionFull(),
		}
	}
	return log
	return
}

func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuration) []ConfigurationInterface {
func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuration) (inf []ConfigurationInterface) {
	inf = nil
	pinf := conf.GetInterface()
	if pinf != nil {
		inf := make([]ConfigurationInterface, len(pinf))
		inf = make([]ConfigurationInterface, len(pinf))
		for k, v := range pinf {
			inf[k] = ConfigurationInterface{
				Name:     v.GetName(),
@@ -227,17 +226,15 @@ func getConfigurationInterfaceFromProto(conf *kproto.Command_GetLog_Configuratio
				Ipv6Addr: v.GetIpv6Address(),
			}
		}
		return inf
	} else {
		return nil
	}
	return
}

func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) ConfigurationLog {
	var log ConfigurationLog
func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) (log *ConfigurationLog) {
	log = nil
	conf := getlog.GetConfiguration()
	if conf != nil {
		log = ConfigurationLog{
		log = &ConfigurationLog{
			Vendor:                  conf.GetVendor(),
			Model:                   conf.GetModel(),
			SerialNumber:            conf.GetSerialNumber(),
@@ -253,35 +250,34 @@ func getConfigurationLogFromProto(getlog *kproto.Command_GetLog) ConfigurationLo
			TlsPort:                 conf.GetTlsPort(),
		}
	}
	return log
	return
}

func getStatisticsLogFromProto(getlog *kproto.Command_GetLog) []StatisticsLog {
func getStatisticsLogFromProto(getlog *kproto.Command_GetLog) (log []StatisticsLog) {
	log = nil
	statics := getlog.GetStatistics()
	if statics != nil {
		slog := make([]StatisticsLog, len(statics))
		log := make([]StatisticsLog, len(statics))
		for k, v := range statics {
			slog[k] = StatisticsLog{
			log[k] = StatisticsLog{
				Type:  convertMessageTypeFromProto(v.GetMessageType()),
				Count: v.GetCount(),
				Bytes: v.GetBytes(),
			}
		}
		return slog
	} else {
		return nil
	}
	return
}

func getLogMessageFromProto(getlog *kproto.Command_GetLog) []byte {
	return getlog.GetMessages()
}

func getLimitsLogFromProto(getlog *kproto.Command_GetLog) LimitsLog {
	var log LimitsLog
func getLimitsLogFromProto(getlog *kproto.Command_GetLog) (log *LimitsLog) {
	log = nil
	limits := getlog.GetLimits()
	if limits != nil {
		log = LimitsLog{
		log = &LimitsLog{
			MaxKeySize:                  limits.GetMaxKeySize(),
			MaxValueSize:                limits.GetMaxValueSize(),
			MaxVersionSize:              limits.GetMaxVersionSize(),
@@ -297,12 +293,12 @@ func getLimitsLogFromProto(getlog *kproto.Command_GetLog) LimitsLog {
			MaxBatchCountPerDevice:      limits.GetMaxBatchCountPerDevice(),
		}
	}
	return log
	return
}

func getDeviceLogFromProto(getlog *kproto.Command_GetLog) DeviceLog {
func getDeviceLogFromProto(getlog *kproto.Command_GetLog) *DeviceLog {
	//TODO: Need more details
	return DeviceLog{
	return &DeviceLog{
		Name: getlog.GetDevice().GetName(),
	}
}
+3 −2
Original line number Diff line number Diff line
package kinetic

import (
	kproto "github.com/yongzhy/kinetic-go/proto"
	"sync"

	kproto "github.com/yongzhy/kinetic-go/proto"
)

// ResponseHandler is the handler for XXXXX_RESPONSE message from drive.
@@ -52,7 +53,7 @@ func (h *ResponseHandler) wait() {
	h.cond.L.Unlock()
}

// Helper function to build a ResponseHandler with call as the Callback.
// NewResponseHandler is helper function to build a ResponseHandler with call as the Callback.
// For each operation, a unique ResponseHandler is requried
func NewResponseHandler(call Callback) *ResponseHandler {
	h := &ResponseHandler{callback: call, done: false, cond: sync.NewCond(&sync.Mutex{})}
Loading