Skip to content

Commit

Permalink
Fix golint for types & functions need comment
Browse files Browse the repository at this point in the history
The files are:
- src/entity/{metrics_container.go, metrics_service.go, service.go}
- src/kubernetes/deployment.go
- src/net/http/{handler.go, responsetest/assert.go}
- src/networkprovider/network.go
- src/prometheuscontroller/query.go
- src/volume/volume.go
- src/web/context.go
  • Loading branch information
sufuf3 committed Jul 23, 2018
1 parent 6c5d2bc commit 18a2de4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/entity/metrics_container.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package entity

// ContainerResourceMetrics is the sructure for Container Resource Metrics
type ContainerResourceMetrics struct {
CPUUsagePercentage float32 `json:"cpuUsagePercentage"`
MemoryUsageBytes float32 `json:"memoryUsageBytes"`
}

// ContainerStatusMetrics is the sructure for Container Status Metrics
type ContainerStatusMetrics struct {
Status string `json:"status"`
WaitingReason string `json:"waitingReason"`
TerminatedReason string `json:"terminatedReason"`
RestartTime int `json:"restartTime"`
}

// ContainerDetailMetrics is the sructure for Container Detail Metrics
type ContainerDetailMetrics struct {
ContainerName string `json:"containerName"`
CreatedAt int `json:"createAt"`
Expand All @@ -22,6 +25,8 @@ type ContainerDetailMetrics struct {
Command []string `json:"command"`
vNIC string `json:"vNic"`
}

// ContainerMetrics is the structure for Container Metrics
type ContainerMetrics struct {
Detail ContainerDetailMetrics `json:"detail"`
Status ContainerStatusMetrics `json:"status"`
Expand Down
1 change: 1 addition & 0 deletions src/entity/metrics_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"k8s.io/api/core/v1"
)

// ServiceMetrics is the structure for Service Metrics
type ServiceMetrics struct {
ServiceName string `json:"serviceName"`
Namespace string `json:"namespace"`
Expand Down
3 changes: 3 additions & 0 deletions src/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"gopkg.in/mgo.v2/bson"
)

// the const for ServiceCollectionName
const (
ServiceCollectionName string = "services"
)

// ServicePort is the structure for service port
type ServicePort struct {
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Port int32 `bson:"port" json:"port" validate:"required"`
TargetPort int `bson:"targetPort" json:"targetPort" validate:"required,max=65535,min=1"`
NodePort int32 `bson:"nodePort" json:"nodePort" validate:"max=32767,min=30000"`
}

// Service is the structure for service
type Service struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Expand Down
5 changes: 4 additions & 1 deletion src/kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//Get the external IP address of node
// CreateDeployment will get the external IP address of node
func (kc *KubeCtl) CreateDeployment(deployment *appsv1.Deployment, namespace string) (*appsv1.Deployment, error) {
return kc.Clientset.AppsV1().Deployments(namespace).Create(deployment)
}

// GetDeployment will get deploy
func (kc *KubeCtl) GetDeployment(name string, namespace string) (*appsv1.Deployment, error) {
return kc.Clientset.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{})
}

// GetDeployments will get deploys
func (kc *KubeCtl) GetDeployments(namespace string) ([]*appsv1.Deployment, error) {
deployments := []*appsv1.Deployment{}
deploymentsList, err := kc.Clientset.AppsV1().Deployments(namespace).List(metav1.ListOptions{})
Expand All @@ -26,6 +28,7 @@ func (kc *KubeCtl) GetDeployments(namespace string) ([]*appsv1.Deployment, error
return deployments, nil
}

// DeleteDeployment will delete deploy
func (kc *KubeCtl) DeleteDeployment(name string, namespace string) error {
return kc.Clientset.AppsV1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{})
}
8 changes: 4 additions & 4 deletions src/net/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/linkernetworks/vortex/src/web"
)

// The interface for native http handler(http.Request and http.ResponseWriter)
// NativeContextHandler is the interface for native http handler(http.Request and http.ResponseWriter)
type NativeContextHandler func(*web.NativeContext)

// CompositeServiceProvider apply mongo client to HandlerFunc
// CompositeServiceHandler apply mongo client to HandlerFunc
func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContextHandler) http.HandlerFunc {
return func(resp http.ResponseWriter, req *http.Request) {
logger.Infoln(req.Method, req.URL)
Expand All @@ -21,10 +21,10 @@ func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContex
}
}

// The interface for restfuul handler(restful.Request,restful.Response)
// RESTfulContextHandler is the interface for restfuul handler(restful.Request,restful.Response)
type RESTfulContextHandler func(*web.Context)

// The wrapper to combine the RESTfulContextHandler with our serviceprovider object
// RESTfulServiceHandler is the wrapper to combine the RESTfulContextHandler with our serviceprovider object
func RESTfulServiceHandler(sp *serviceprovider.Container, handler RESTfulContextHandler) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
ctx := web.Context{sp, req, resp}
Expand Down
3 changes: 3 additions & 0 deletions src/net/http/responsetest/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/stretchr/testify/assert"
)

// AssertStatusEqual will assert equal status
func AssertStatusEqual(t *testing.T, resp *httptest.ResponseRecorder, status int) {
assert.Equal(t, status, resp.Code)
}

// AssertErrorMessage will assert error message
func AssertErrorMessage(t *testing.T, resp *httptest.ResponseRecorder, msg string) (err error) {
var payload = response.ErrorPayload{}
var out = resp.Body.Bytes()
Expand All @@ -31,6 +33,7 @@ func AssertErrorMessage(t *testing.T, resp *httptest.ResponseRecorder, msg strin
return err
}

// AssertError will assert error
func AssertError(t *testing.T, resp *httptest.ResponseRecorder) (err error) {
var payload = response.ErrorPayload{}
var out = resp.Body.Bytes()
Expand Down
3 changes: 3 additions & 0 deletions src/networkprovider/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/linkernetworks/vortex/src/utils"
)

// NetworkProvider is the structure for Network Provider
type NetworkProvider interface {
CreateNetwork(sp *serviceprovider.Container) error
DeleteNetwork(sp *serviceprovider.Container) error
}

// GetNetworkProvider will get network provider if you gave *entity.Network
func GetNetworkProvider(network *entity.Network) (NetworkProvider, error) {
switch network.Type {
case entity.OVSKernelspaceNetworkType:
Expand All @@ -32,6 +34,7 @@ func GetNetworkProvider(network *entity.Network) (NetworkProvider, error) {
}
}

// GenerateBridgeName will generate bridge name
func GenerateBridgeName(datapathType, networkName string) string {
tmp := fmt.Sprintf("%s%s", datapathType, networkName)
str := utils.SHA256String(tmp)
Expand Down
1 change: 1 addition & 0 deletions src/prometheuscontroller/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"golang.org/x/net/context"
)

// Expression is the structure for expression
type Expression struct {
Metrics []string `json:"metrics"`
QueryLabels map[string]string `json:"queryLabels"`
Expand Down
2 changes: 2 additions & 0 deletions src/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func getStorageClassName(session *mongo.Session, storageName string) (string, er
return storage.StorageClassName, err
}

// CreateVolume is a function to create volume
func CreateVolume(sp *serviceprovider.Container, volume *entity.Volume) error {
namespace := "default"
session := sp.Mongo.NewSession()
Expand All @@ -57,6 +58,7 @@ func CreateVolume(sp *serviceprovider.Container, volume *entity.Volume) error {
return err
}

// DeleteVolume is a function to delete volume
func DeleteVolume(sp *serviceprovider.Container, volume *entity.Volume) error {
namespace := "default"
//Check the pod
Expand Down
4 changes: 2 additions & 2 deletions src/web/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"github.com/linkernetworks/vortex/src/serviceprovider"
)

// The struct to combine the restful message with our own serviceProvider
// Context is the struct to combine the restful message with our own serviceProvider
type Context struct {
ServiceProvider *serviceprovider.Container
Request *restful.Request
Response *restful.Response
}

// The struct to combine the native http message with our own serviceProvider
// NativeContext is the struct to combine the native http message with our own serviceProvider
type NativeContext struct {
ServiceProvider *serviceprovider.Container
Request *http.Request
Expand Down

0 comments on commit 18a2de4

Please sign in to comment.