Skip to content

Commit

Permalink
refactor: update variable name with initialisms (#361)
Browse files Browse the repository at this point in the history
Because

- We want to standardize the naming convention on variable name with
initialisms

This commit

- Enable stylecheck in golangci-lint
- Update variable name
- Add golangci-lint Github Action
- Remove JSON auto-formatter since it will break the readability
  • Loading branch information
donch1989 committed Jan 13, 2024
1 parent 2214e73 commit c965694
Show file tree
Hide file tree
Showing 25 changed files with 519 additions and 485 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint

on:
push:
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: --timeout=10m
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
linters:
enable:
- stylecheck

linters-settings:
stylecheck:
checks: [ "all" ]
6 changes: 3 additions & 3 deletions cmd/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
)

type PrebuiltConnector struct {
Id string `json:"id"`
Uid string `json:"uid"`
ID string `json:"id"`
UID string `json:"uid"`
Owner string `json:"owner"`
ConnectorDefinitionUid string `json:"connector_definition_uid"`
ConnectorDefinitionUID string `json:"connector_definition_uid"`
Configuration interface{} `json:"configuration"`
Task string `json:"task"`
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
github.com/iancoleman/strcase v0.2.0
github.com/influxdata/influxdb-client-go/v2 v2.12.3
github.com/instill-ai/component v0.8.0-beta.0.20240112032605-792559e0b538
github.com/instill-ai/connector v0.9.0-beta.0.20240112155927-34d1a20784b4
github.com/instill-ai/operator v0.6.0-beta.0.20240108023644-8644208adde4
github.com/instill-ai/component v0.8.0-beta.0.20240112193844-0946e6a23d49
github.com/instill-ai/connector v0.9.0-beta.0.20240112194738-96d210767a16
github.com/instill-ai/operator v0.6.0-beta.0.20240112194611-f3b1b526ee2e
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240105094938-3a71d8f7a812
github.com/instill-ai/usage-client v0.2.4-alpha.0.20231206162018-6ccbff13136b
github.com/instill-ai/x v0.3.0-alpha.0.20231219052200-6230a89e386c
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,12 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0
github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/instill-ai/component v0.8.0-beta.0.20240112032605-792559e0b538 h1:wHkWugd03PwOrupcwrd8/FBaeQhKyvK0xmEK6vwmZVM=
github.com/instill-ai/component v0.8.0-beta.0.20240112032605-792559e0b538/go.mod h1:fWyVPJVJ4WyFSQMgWCc7KvcS7m9QpdS3VXCL2CZE8OY=
github.com/instill-ai/connector v0.9.0-beta.0.20240112155927-34d1a20784b4 h1:jm6kK/Sd4fZ40QihsN7+2H+dsr0Lx26Ip/VcMrKdSvk=
github.com/instill-ai/connector v0.9.0-beta.0.20240112155927-34d1a20784b4/go.mod h1:meUwooBcW0NQqNA/9cfdrDGWA9VqK5hjLIvjtBxK4bg=
github.com/instill-ai/operator v0.6.0-beta.0.20240108023644-8644208adde4 h1:gNxhkOnemxPMpN4vUkOXf1TilyN1kJUK6QQijoaboHg=
github.com/instill-ai/operator v0.6.0-beta.0.20240108023644-8644208adde4/go.mod h1:exFYtKdZFyzAczduFxQlD4X7+/B4OLYJ3ihA7j8Kcsg=
github.com/instill-ai/component v0.8.0-beta.0.20240112193844-0946e6a23d49 h1:Kc6U1LnA7KgsJkk3kN9RxctsX8C6UKtXRqmi9/eR3VY=
github.com/instill-ai/component v0.8.0-beta.0.20240112193844-0946e6a23d49/go.mod h1:fWyVPJVJ4WyFSQMgWCc7KvcS7m9QpdS3VXCL2CZE8OY=
github.com/instill-ai/connector v0.9.0-beta.0.20240112194738-96d210767a16 h1:TuBwAOnV1rWaeT9cFD/zi0bIIKee5JfQKLv7mDy8tfs=
github.com/instill-ai/connector v0.9.0-beta.0.20240112194738-96d210767a16/go.mod h1:T6ifUP06EBz61cG9rW9wLk96reWokHCOTocDOj1V6yo=
github.com/instill-ai/operator v0.6.0-beta.0.20240112194611-f3b1b526ee2e h1:H1dGj/zbZINXURrS3+Kq7vjb5M7FjNRhaztmwozrw+8=
github.com/instill-ai/operator v0.6.0-beta.0.20240112194611-f3b1b526ee2e/go.mod h1:ROHmvSRF7lQD6/7uOHeBVNcsuQqxPoMtDc6so8XNFwU=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240105094938-3a71d8f7a812 h1:n1EQFT0NeXkmiCD/YtoLG+b/OPo2tNg7MVK0dHNFlvk=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240105094938-3a71d8f7a812/go.mod h1:jhEL0SauySMoPLVvx105DWyThju9sYTbsXIySVCArmM=
github.com/instill-ai/usage-client v0.2.4-alpha.0.20231206162018-6ccbff13136b h1:YwXracXgTWxaPfIsbC3uaZFjGO0E2y1e3hK9ZUq7ipE=
Expand Down
8 changes: 4 additions & 4 deletions internal/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ const (
type Namespace struct {
NsType NamespaceType
NsID string
NsUid uuid.UUID
NsUID uuid.UUID
}

func (ns Namespace) String() string {
return fmt.Sprintf("%s/%s", ns.NsType, ns.NsUid.String())
return fmt.Sprintf("%s/%s", ns.NsType, ns.NsUID.String())
}

func UserUidToUserPermalink(userUid uuid.UUID) string {
return fmt.Sprintf("users/%s", userUid.String())
func UserUIDToUserPermalink(userUID uuid.UUID) string {
return fmt.Sprintf("users/%s", userUID.String())
}

func ConvertConnectorToResourceName(connectorName string) string {
Expand Down
18 changes: 9 additions & 9 deletions pkg/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type ACLClient struct {
client *openfgaClient.OpenFgaClient
authorizationModelId *string
authorizationModelID *string
}

type Relation struct {
Expand All @@ -24,15 +24,15 @@ type Relation struct {
func NewACLClient(c *openfgaClient.OpenFgaClient, a *string) ACLClient {
return ACLClient{
client: c,
authorizationModelId: a,
authorizationModelID: a,
}
}

func (c *ACLClient) SetOwner(objectType string, objectUID uuid.UUID, ownerType string, ownerUID uuid.UUID) error {
var err error
readOptions := openfgaClient.ClientReadOptions{}
writeOptions := openfgaClient.ClientWriteOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}

readBody := openfgaClient.ClientReadRequest{
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *ACLClient) SetPipelinePermissionMap(pipeline *datamodel.Pipeline) error
func (c *ACLClient) SetPipelinePermission(pipelineUID uuid.UUID, user string, role string, enable bool) error {
var err error
options := openfgaClient.ClientWriteOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}

_ = c.DeletePipelinePermission(pipelineUID, user)
Expand All @@ -141,7 +141,7 @@ func (c *ACLClient) SetPipelinePermission(pipelineUID uuid.UUID, user string, ro
func (c *ACLClient) DeletePipelinePermission(pipelineUID uuid.UUID, user string) error {
// var err error
options := openfgaClient.ClientWriteOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}

for _, role := range []string{"admin", "writer", "executor", "reader"} {
Expand All @@ -162,7 +162,7 @@ func (c *ACLClient) DeletePipelinePermission(pipelineUID uuid.UUID, user string)
func (c *ACLClient) Purge(objectType string, objectUID uuid.UUID) error {
readOptions := openfgaClient.ClientReadOptions{}
writeOptions := openfgaClient.ClientWriteOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}

readBody := openfgaClient.ClientReadRequest{
Expand Down Expand Up @@ -193,7 +193,7 @@ func (c *ACLClient) Purge(objectType string, objectUID uuid.UUID) error {
func (c *ACLClient) CheckPermission(objectType string, objectUID uuid.UUID, userType string, userUID uuid.UUID, code string, role string) (bool, error) {

options := openfgaClient.ClientCheckOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}
body := openfgaClient.ClientCheckRequest{
User: fmt.Sprintf("%s:%s", userType, userUID.String()),
Expand Down Expand Up @@ -228,7 +228,7 @@ func (c *ACLClient) CheckPermission(objectType string, objectUID uuid.UUID, user
func (c *ACLClient) CheckPublicExecutable(objectType string, objectUID uuid.UUID) (bool, error) {

options := openfgaClient.ClientCheckOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}
body := openfgaClient.ClientCheckRequest{
User: "user:*",
Expand All @@ -249,7 +249,7 @@ func (c *ACLClient) CheckPublicExecutable(objectType string, objectUID uuid.UUID
func (c *ACLClient) ListPermissions(objectType string, userType string, userUID uuid.UUID, role string) ([]uuid.UUID, error) {

options := openfgaClient.ClientListObjectsOptions{
AuthorizationModelId: c.authorizationModelId,
AuthorizationModelId: c.authorizationModelID,
}
userUIDStr := "*"
if userUID != uuid.Nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ const HeaderUserUIDKey = "Instill-User-Uid"
const HeaderVisitorUIDKey = "Instill-Visitor-Uid"
const HeaderAuthTypeKey = "Instill-Auth-Type"
const HeaderInstillCodeKey = "Instill-Share-Code"
const StartConnectorId = "start"
const EndConnectorId = "end"
const StartConnectorID = "start"
const EndConnectorID = "end"
const ReturnTracesKey = "instill-return-traces"
2 changes: 1 addition & 1 deletion pkg/datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Recipe struct {
}

type Component struct {
Id string `json:"id"`
ID string `json:"id"`
DefinitionName string `json:"definition_name"`
ResourceName string `json:"resource_name"`
Configuration *structpb.Struct `json:"configuration"`
Expand Down
20 changes: 10 additions & 10 deletions pkg/handler/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (h *PrivateHandler) CheckConnector(ctx context.Context, req *pipelinePB.Che
return resp, err
}

connector, err := h.service.GetConnectorByUIDAdmin(ctx, connUID, service.VIEW_BASIC)
connector, err := h.service.GetConnectorByUIDAdmin(ctx, connUID, service.ViewBasic)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -612,7 +612,7 @@ func (h *PublicHandler) updateNamespaceConnector(ctx context.Context, req Update
return nil, st.Err()
}

existedConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_FULL, false)
existedConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewFull, false)
if err != nil {
span.SetStatus(1, err.Error())
return nil, err
Expand Down Expand Up @@ -655,7 +655,7 @@ func (h *PublicHandler) updateNamespaceConnector(ctx context.Context, req Update
}

if mask.IsEmpty() {
existedConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_FULL, true)
existedConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewFull, true)
if err != nil {
span.SetStatus(1, err.Error())
return nil, err
Expand Down Expand Up @@ -757,7 +757,7 @@ func (h *PublicHandler) deleteNamespaceConnector(ctx context.Context, req Delete
return err
}

dbConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_BASIC, true)
dbConnector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewBasic, true)
if err != nil {
span.SetStatus(1, err.Error())
return err
Expand Down Expand Up @@ -841,7 +841,7 @@ func (h *PublicHandler) connectNamespaceConnector(ctx context.Context, req Conne
return nil, err
}

connector, err = h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_BASIC, true)
connector, err = h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewBasic, true)
if err != nil {
span.SetStatus(1, err.Error())
return nil, err
Expand Down Expand Up @@ -1097,7 +1097,7 @@ func (h *PublicHandler) watchNamespaceConnector(ctx context.Context, req WatchNa
return pipelinePB.Connector_STATE_UNSPECIFIED, err
}

connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_BASIC, true)
connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewBasic, true)
if err != nil {
span.SetStatus(1, err.Error())
logger.Info(string(custom_otel.NewLogMessage(
Expand Down Expand Up @@ -1153,7 +1153,7 @@ func (h *PublicHandler) testNamespaceConnector(ctx context.Context, req TestName
return pipelinePB.Connector_STATE_UNSPECIFIED, err
}

connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_BASIC, true)
connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewBasic, true)
if err != nil {
span.SetStatus(1, err.Error())
return pipelinePB.Connector_STATE_UNSPECIFIED, err
Expand Down Expand Up @@ -1219,7 +1219,7 @@ func (h *PublicHandler) executeNamespaceConnector(ctx context.Context, req Execu
return nil, err
}

connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.VIEW_FULL, true)
connector, err := h.service.GetNamespaceConnectorByID(ctx, ns, authUser, connID, service.ViewFull, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1247,14 +1247,14 @@ func (h *PublicHandler) executeNamespaceConnector(ctx context.Context, req Execu
}

dataPoint := utils.ConnectorUsageMetricData{
OwnerUID: ns.NsUid.String(),
OwnerUID: ns.NsUID.String(),
OwnerType: ownerType,
UserUID: authUser.UID.String(),
UserType: mgmtPB.OwnerType_OWNER_TYPE_USER, // TODO: currently only support /users type, will change after beta
ConnectorID: connector.Id,
ConnectorUID: connector.Uid,
ConnectorExecuteUID: logUUID.String(),
ConnectorDefinitionUid: connector.ConnectorDefinition.Uid,
ConnectorDefinitionUID: connector.ConnectorDefinition.Uid,
ExecuteTime: startTime.Format(time.RFC3339Nano),
}

Expand Down
1 change: 1 addition & 0 deletions pkg/handler/formdata_handler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:stylecheck
package handler

import (
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

func (h *PublicHandler) GetOperation(ctx context.Context, req *pipelinePB.GetOperationRequest) (*pipelinePB.GetOperationResponse, error) {

operationId, err := resource.GetOperationID(req.Name)
operationID, err := resource.GetOperationID(req.Name)
if err != nil {
return &pipelinePB.GetOperationResponse{}, err
}
operation, err := h.service.GetOperation(ctx, operationId)
operation, err := h.service.GetOperation(ctx, operationID)
if err != nil {
return &pipelinePB.GetOperationResponse{}, err
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/handler/operator_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (h *PrivateHandler) LookUpOperatorDefinitionAdmin(ctx context.Context, req
return resp, err
}

dbDef, err := h.service.GetOperatorDefinitionById(ctx, connID)
dbDef, err := h.service.GetOperatorDefinitionByID(ctx, connID)
if err != nil {
return resp, err
}
resp.OperatorDefinition = proto.Clone(dbDef).(*pipelinePB.OperatorDefinition)
if parseView(int32(*req.GetView().Enum())) == service.VIEW_BASIC {
if parseView(int32(*req.GetView().Enum())) == service.ViewBasic {
resp.OperatorDefinition.Spec = nil
}
resp.OperatorDefinition.Name = fmt.Sprintf("operator-definitions/%s", resp.OperatorDefinition.GetId())
Expand All @@ -59,10 +59,10 @@ func (h *PublicHandler) ListOperatorDefinitions(ctx context.Context, req *pipeli
pageToken := req.GetPageToken()
isBasicView := (req.GetView() == pipelinePB.OperatorDefinition_VIEW_BASIC) || (req.GetView() == pipelinePB.OperatorDefinition_VIEW_UNSPECIFIED)

prevLastUid := ""
prevLastUID := ""

if pageToken != "" {
_, prevLastUid, err = paginate.DecodeToken(pageToken)
_, prevLastUID, err = paginate.DecodeToken(pageToken)
if err != nil {
st, err := sterr.CreateErrorBadRequest(
fmt.Sprintf("[db] list operator error: %s", err.Error()),
Expand All @@ -89,9 +89,9 @@ func (h *PublicHandler) ListOperatorDefinitions(ctx context.Context, req *pipeli
defs := h.service.ListOperatorDefinitions(ctx)

startIdx := 0
lastUid := ""
lastUID := ""
for idx, def := range defs {
if def.Uid == prevLastUid {
if def.Uid == prevLastUID {
startIdx = idx + 1
break
}
Expand All @@ -101,13 +101,13 @@ func (h *PublicHandler) ListOperatorDefinitions(ctx context.Context, req *pipeli
for i := 0; i < int(pageSize) && startIdx+i < len(defs); i++ {
def := proto.Clone(defs[startIdx+i]).(*pipelinePB.OperatorDefinition)
page = append(page, def)
lastUid = def.Uid
lastUID = def.Uid
}

nextPageToken := ""

if startIdx+len(page) < len(defs) {
nextPageToken = paginate.EncodeToken(time.Time{}, lastUid)
nextPageToken = paginate.EncodeToken(time.Time{}, lastUID)
}
for _, def := range page {
def.Name = fmt.Sprintf("operator-definitions/%s", def.Id)
Expand Down Expand Up @@ -143,7 +143,7 @@ func (h *PublicHandler) GetOperatorDefinition(ctx context.Context, req *pipeline
}
isBasicView := (req.GetView() == pipelinePB.OperatorDefinition_VIEW_BASIC) || (req.GetView() == pipelinePB.OperatorDefinition_VIEW_UNSPECIFIED)

dbDef, err := h.service.GetOperatorDefinitionById(ctx, connID)
dbDef, err := h.service.GetOperatorDefinitionByID(ctx, connID)
if err != nil {
span.SetStatus(1, err.Error())
return resp, err
Expand Down
Loading

0 comments on commit c965694

Please sign in to comment.