A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
style: remove unnecessary functions
LinkinStara28a2c5bb6c2
diff --git a/charts/.idea/.gitignore b/charts/.idea/.gitignoredeleted file mode 100644index 13566b81..00000000--- a/charts/.idea/.gitignore+++ /dev/null@@ -1,8 +0,0 @@-# Default ignored files-/shelf/-/workspace.xml-# Editor-based HTTP Client requests-/httpRequests/-# Datasource local storage ignored files-/dataSources/-/dataSources.local.xmldiff --git a/charts/.idea/charts.iml b/charts/.idea/charts.imldeleted file mode 100644index 5e764c4f..00000000--- a/charts/.idea/charts.iml+++ /dev/null@@ -1,9 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<module type="WEB_MODULE" version="4">- <component name="Go" enabled="true" />- <component name="NewModuleRootManager">- <content url="file://$MODULE_DIR$" />- <orderEntry type="inheritedJdk" />- <orderEntry type="sourceFolder" forTests="false" />- </component>-</module>\ No newline at end of filediff --git a/charts/.idea/modules.xml b/charts/.idea/modules.xmldeleted file mode 100644index 442a908c..00000000--- a/charts/.idea/modules.xml+++ /dev/null@@ -1,8 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<project version="4">- <component name="ProjectModuleManager">- <modules>- <module fileurl="file://$PROJECT_DIR$/.idea/charts.iml" filepath="$PROJECT_DIR$/.idea/charts.iml" />- </modules>- </component>-</project>\ No newline at end of filediff --git a/charts/.idea/vcs.xml b/charts/.idea/vcs.xmldeleted file mode 100644index 6c0b8635..00000000--- a/charts/.idea/vcs.xml+++ /dev/null@@ -1,6 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<project version="4">- <component name="VcsDirectoryMappings">- <mapping directory="$PROJECT_DIR$/.." vcs="Git" />- </component>-</project>\ No newline at end of filediff --git a/deployments/README.md b/deployments/README.mddeleted file mode 100644index 24810d0f..00000000--- a/deployments/README.md+++ /dev/null@@ -1,3 +0,0 @@-# /deployments--IaaS, PaaS, system and container orchestration deployment configurations and templates (docker-compose, kubernetes/helm, mesos, terraform, bosh).diff --git a/docs/docs.go b/docs/docs.goindex bbdc7c89..51596b91 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -3962,36 +3962,6 @@ const docTemplate = `{}}},- "schema.AddCollectionGroupReq": {- "type": "object",- "required": [- "create_time",- "default_group",- "name",- "update_time",- "user_id"- ],- "properties": {- "create_time": {- "type": "string"- },- "default_group": {- "description": "mark this group is default, default 1",- "type": "integer"- },- "name": {- "description": "the collection group name",- "type": "string",- "maxLength": 50- },- "update_time": {- "type": "string"- },- "user_id": {- "type": "integer"- }- }- },"schema.AddCommentReq": {"type": "object","required": [@@ -4025,28 +3995,6 @@ const docTemplate = `{}}},- "schema.AddNotificationReadReq": {- "type": "object",- "required": [- "is_read",- "message_id",- "user_id"- ],- "properties": {- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.AddReportReq": {"type": "object","required": [@@ -4070,9 +4018,6 @@ const docTemplate = `{}}},- "schema.AddUserGroupReq": {- "type": "object"- },"schema.AdminSetQuestionStatusRequest": {"type": "object","properties": {@@ -4386,35 +4331,6 @@ const docTemplate = `{}}},- "schema.GetNotificationReadResp": {- "type": "object",- "properties": {- "created_at": {- "description": "create time",- "type": "string"- },- "id": {- "description": "id",- "type": "integer"- },- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "updated_at": {- "description": "update time",- "type": "string"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.GetOtherUserInfoByUsernameResp": {"type": "object","properties": {@@ -4778,18 +4694,6 @@ const docTemplate = `{}}},- "schema.GetUserGroupResp": {- "type": "object",- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },- "schema.GetUserInfoResp": {- "type": "object"- },"schema.GetUserPageResp": {"type": "object","properties": {@@ -5139,18 +5043,6 @@ const docTemplate = `{}}},- "schema.RemoveNotificationReadReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "id",- "type": "integer"- }- }- },"schema.RemoveQuestionReq": {"type": "object","required": [@@ -5175,18 +5067,6 @@ const docTemplate = `{}}},- "schema.RemoveUserGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },"schema.ReportHandleReq": {"type": "object","required": [@@ -5401,35 +5281,6 @@ const docTemplate = `{}}},- "schema.UpdateCollectionGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "create_time": {- "type": "string"- },- "default_group": {- "description": "mark this group is default, default 1",- "type": "integer"- },- "id": {- "type": "integer"- },- "name": {- "description": "the collection group name",- "type": "string",- "maxLength": 50- },- "update_time": {- "type": "string"- },- "user_id": {- "type": "integer"- }- }- },"schema.UpdateCommentReq": {"type": "object","required": [@@ -5505,30 +5356,6 @@ const docTemplate = `{}}},- "schema.UpdateNotificationReadReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "id",- "type": "integer"- },- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.UpdateSMTPConfigReq": {"type": "object","properties": {@@ -5626,18 +5453,6 @@ const docTemplate = `{}}},- "schema.UpdateUserGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },"schema.UpdateUserStatusReq": {"type": "object","required": [diff --git a/docs/swagger.json b/docs/swagger.jsonindex 3bffef99..bd08e554 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -3950,36 +3950,6 @@}}},- "schema.AddCollectionGroupReq": {- "type": "object",- "required": [- "create_time",- "default_group",- "name",- "update_time",- "user_id"- ],- "properties": {- "create_time": {- "type": "string"- },- "default_group": {- "description": "mark this group is default, default 1",- "type": "integer"- },- "name": {- "description": "the collection group name",- "type": "string",- "maxLength": 50- },- "update_time": {- "type": "string"- },- "user_id": {- "type": "integer"- }- }- },"schema.AddCommentReq": {"type": "object","required": [@@ -4013,28 +3983,6 @@}}},- "schema.AddNotificationReadReq": {- "type": "object",- "required": [- "is_read",- "message_id",- "user_id"- ],- "properties": {- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.AddReportReq": {"type": "object","required": [@@ -4058,9 +4006,6 @@}}},- "schema.AddUserGroupReq": {- "type": "object"- },"schema.AdminSetQuestionStatusRequest": {"type": "object","properties": {@@ -4374,35 +4319,6 @@}}},- "schema.GetNotificationReadResp": {- "type": "object",- "properties": {- "created_at": {- "description": "create time",- "type": "string"- },- "id": {- "description": "id",- "type": "integer"- },- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "updated_at": {- "description": "update time",- "type": "string"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.GetOtherUserInfoByUsernameResp": {"type": "object","properties": {@@ -4766,18 +4682,6 @@}}},- "schema.GetUserGroupResp": {- "type": "object",- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },- "schema.GetUserInfoResp": {- "type": "object"- },"schema.GetUserPageResp": {"type": "object","properties": {@@ -5127,18 +5031,6 @@}}},- "schema.RemoveNotificationReadReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "id",- "type": "integer"- }- }- },"schema.RemoveQuestionReq": {"type": "object","required": [@@ -5163,18 +5055,6 @@}}},- "schema.RemoveUserGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },"schema.ReportHandleReq": {"type": "object","required": [@@ -5389,35 +5269,6 @@}}},- "schema.UpdateCollectionGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "create_time": {- "type": "string"- },- "default_group": {- "description": "mark this group is default, default 1",- "type": "integer"- },- "id": {- "type": "integer"- },- "name": {- "description": "the collection group name",- "type": "string",- "maxLength": 50- },- "update_time": {- "type": "string"- },- "user_id": {- "type": "integer"- }- }- },"schema.UpdateCommentReq": {"type": "object","required": [@@ -5493,30 +5344,6 @@}}},- "schema.UpdateNotificationReadReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "id",- "type": "integer"- },- "is_read": {- "description": "read status(unread: 1; read 2)",- "type": "integer"- },- "message_id": {- "description": "message id",- "type": "integer"- },- "user_id": {- "description": "user id",- "type": "integer"- }- }- },"schema.UpdateSMTPConfigReq": {"type": "object","properties": {@@ -5614,18 +5441,6 @@}}},- "schema.UpdateUserGroupReq": {- "type": "object",- "required": [- "id"- ],- "properties": {- "id": {- "description": "user group id",- "type": "integer"- }- }- },"schema.UpdateUserStatusReq": {"type": "object","required": [diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex c0f1febb..cf6bcd49 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -35,28 +35,6 @@ definitions:verify:type: booleantype: object- schema.AddCollectionGroupReq:- properties:- create_time:- type: string- default_group:- description: mark this group is default, default 1- type: integer- name:- description: the collection group name- maxLength: 50- type: string- update_time:- type: string- user_id:- type: integer- required:- - create_time- - default_group- - name- - update_time- - user_id- type: objectschema.AddCommentReq:properties:mention_username_list:@@ -81,22 +59,6 @@ definitions:- original_text- parsed_texttype: object- schema.AddNotificationReadReq:- properties:- is_read:- description: 'read status(unread: 1; read 2)'- type: integer- message_id:- description: message id- type: integer- user_id:- description: user id- type: integer- required:- - is_read- - message_id- - user_id- type: objectschema.AddReportReq:properties:content:@@ -114,8 +76,6 @@ definitions:- object_id- report_typetype: object- schema.AddUserGroupReq:- type: objectschema.AdminSetQuestionStatusRequest:properties:question_id:@@ -340,27 +300,6 @@ definitions:description: tag idtype: stringtype: object- schema.GetNotificationReadResp:- properties:- created_at:- description: create time- type: string- id:- description: id- type: integer- is_read:- description: 'read status(unread: 1; read 2)'- type: integer- message_id:- description: message id- type: integer- updated_at:- description: update time- type: string- user_id:- description: user id- type: integer- type: objectschema.GetOtherUserInfoByUsernameResp:properties:answer_count:@@ -627,14 +566,6 @@ definitions:description: tag idtype: stringtype: object- schema.GetUserGroupResp:- properties:- id:- description: user group id- type: integer- type: object- schema.GetUserInfoResp:- type: objectschema.GetUserPageResp:properties:avatar:@@ -891,14 +822,6 @@ definitions:required:- comment_idtype: object- schema.RemoveNotificationReadReq:- properties:- id:- description: id- type: integer- required:- - id- type: objectschema.RemoveQuestionReq:properties:id:@@ -915,14 +838,6 @@ definitions:required:- tag_idtype: object- schema.RemoveUserGroupReq:- properties:- id:- description: user group id- type: integer- required:- - id- type: objectschema.ReportHandleReq:properties:flagged_content:@@ -1074,26 +989,6 @@ definitions:slug_name:type: stringtype: object- schema.UpdateCollectionGroupReq:- properties:- create_time:- type: string- default_group:- description: mark this group is default, default 1- type: integer- id:- type: integer- name:- description: the collection group name- maxLength: 50- type: string- update_time:- type: string- user_id:- type: integer- required:- - id- type: objectschema.UpdateCommentReq:properties:comment_id:@@ -1149,23 +1044,6 @@ definitions:required:- display_nametype: object- schema.UpdateNotificationReadReq:- properties:- id:- description: id- type: integer- is_read:- description: 'read status(unread: 1; read 2)'- type: integer- message_id:- description: message id- type: integer- user_id:- description: user id- type: integer- required:- - id- type: objectschema.UpdateSMTPConfigReq:properties:encryption:@@ -1236,14 +1114,6 @@ definitions:- synonym_tag_list- tag_idtype: object- schema.UpdateUserGroupReq:- properties:- id:- description: user group id- type: integer- required:- - id- type: objectschema.UpdateUserStatusReq:properties:status:diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.goindex 5865e1ef..9ccd519a 100644--- a/internal/base/constant/constant.go+++ b/internal/base/constant/constant.go@@ -3,10 +3,7 @@ package constantimport "time"const (- Default_PageSize = 20 //Default number of pages- Key_UserID = "_UserID" //session userid- LoginUserID = "login_user_id"- LoginUserVerify = "login_user_verify"+ Default_PageSize = 20 //Default number of pagesUserStatusChangedCacheKey = "answer:user:status:"UserStatusChangedCacheTime = 7 * 24 * time.HourUserTokenCacheKey = "answer:user:token:"diff --git a/internal/controller/revision_controller.go b/internal/controller/revision_controller.goindex 2756763f..21aa1b7c 100644--- a/internal/controller/revision_controller.go+++ b/internal/controller/revision_controller.go@@ -19,26 +19,6 @@ func NewRevisionController(revisionListService *service.RevisionService) *Revisireturn &RevisionController{revisionListService: revisionListService}}-// GetRevision get revision one-// @Summary get revision one-// @Description get revision one-// @Tags Revision-// @Accept json-// @Produce json-// @Param id path int true "revisionid"-// @Success 200 {object} handler.RespBody{data=schema.GetRevisionResp}-// Router /revision/{id} [get]-func (rc *RevisionController) GetRevision(ctx *gin.Context) {- id := ctx.Param("id")- if id == "0" {- handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), nil)- return- }-- resp, err := rc.revisionListService.GetRevision(ctx, id)- handler.HandleResponse(ctx, err, resp)-}-// GetRevisionList godoc// @Summary get revision list// @Description get revision listdiff --git a/internal/controller_backyard/user_backyard_controller.go b/internal/controller_backyard/user_backyard_controller.goindex e87b50c6..039d9ce3 100644--- a/internal/controller_backyard/user_backyard_controller.go+++ b/internal/controller_backyard/user_backyard_controller.go@@ -3,10 +3,8 @@ package controller_backyardimport ("github.com/gin-gonic/gin""github.com/segmentfault/answer/internal/base/handler"- "github.com/segmentfault/answer/internal/base/reason""github.com/segmentfault/answer/internal/schema""github.com/segmentfault/answer/internal/service/user_backyard"- "github.com/segmentfault/pacman/errors")// UserBackyardController user controller@@ -39,27 +37,6 @@ func (uc *UserBackyardController) UpdateUserStatus(ctx *gin.Context) {handler.HandleResponse(ctx, err, nil)}-// GetUserInfo get user one-// @Summary get user one-// @Description get user one-// @Security ApiKeyAuth-// @Tags admin-// @Accept json-// @Produce json-// @Param id path int true "userid"-// @Success 200 {object} handler.RespBody{data=schema.GetUserInfoResp}-// Router /user/{id} [get]-func (uc *UserBackyardController) GetUserInfo(ctx *gin.Context) {- userID := ctx.Query("user_id")- if len(userID) == 0 {- handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), nil)- return- }-- resp, err := uc.userService.GetUserInfo(ctx, userID)- handler.HandleResponse(ctx, err, resp)-}-// GetUserPage get user page// @Summary get user page// @Description get user pagediff --git a/internal/schema/notification_read_schema.go b/internal/schema/notification_read_schema.godeleted file mode 100644index 0816866c..00000000--- a/internal/schema/notification_read_schema.go+++ /dev/null@@ -1,71 +0,0 @@-package schema--import "time"--// AddNotificationReadReq add notification read record request-type AddNotificationReadReq struct {- // user id- UserID int64 `validate:"required" comment:"user id" json:"user_id"`- // message id- MessageID int64 `validate:"required" comment:"message id" json:"message_id"`- // read status(unread: 1; read 2)- IsRead int `validate:"required" comment:"read status(unread: 1; read 2)" json:"is_read"`-}--// RemoveNotificationReadReq delete notification read record request-type RemoveNotificationReadReq struct {- // id- ID int `validate:"required" comment:"id" json:"id"`-}--// UpdateNotificationReadReq update notification read record request-type UpdateNotificationReadReq struct {- // id- ID int `validate:"required" comment:"id" json:"id"`- // user id- UserID int64 `validate:"omitempty" comment:"user id" json:"user_id"`- // message id- MessageID int64 `validate:"omitempty" comment:"message id" json:"message_id"`- // read status(unread: 1; read 2)- IsRead int `validate:"omitempty" comment:"read status(unread: 1; read 2)" json:"is_read"`-}--// GetNotificationReadListReq get notification read record list all request-type GetNotificationReadListReq struct {- // user id- UserID int64 `validate:"omitempty" comment:"user id" form:"user_id"`- // message id- MessageID int64 `validate:"omitempty" comment:"message id" form:"message_id"`- // read status(unread: 1; read 2)- IsRead int `validate:"omitempty" comment:"read status(unread: 1; read 2)" form:"is_read"`-}--// GetNotificationReadWithPageReq get notification read record list page request-type GetNotificationReadWithPageReq struct {- // page- Page int `validate:"omitempty,min=1" form:"page"`- // page size- PageSize int `validate:"omitempty,min=1" form:"page_size"`- // user id- UserID int64 `validate:"omitempty" comment:"user id" form:"user_id"`- // message id- MessageID int64 `validate:"omitempty" comment:"message id" form:"message_id"`- // read status(unread: 1; read 2)- IsRead int `validate:"omitempty" comment:"read status(unread: 1; read 2)" form:"is_read"`-}--// GetNotificationReadResp get notification read record response-type GetNotificationReadResp struct {- // id- ID int `json:"id"`- // create time- CreatedAt time.Time `json:"created_at"`- // update time- UpdatedAt time.Time `json:"updated_at"`- // user id- UserID int64 `json:"user_id"`- // message id- MessageID int64 `json:"message_id"`- // read status(unread: 1; read 2)- IsRead int `json:"is_read"`-}diff --git a/internal/schema/user_group_schema.go b/internal/schema/user_group_schema.godeleted file mode 100644index 5ebac4a1..00000000--- a/internal/schema/user_group_schema.go+++ /dev/null@@ -1,35 +0,0 @@-package schema--// AddUserGroupReq add user group request-type AddUserGroupReq struct {-}--// RemoveUserGroupReq delete user group request-type RemoveUserGroupReq struct {- // user group id- ID int64 `validate:"required" comment:"user group id" json:"id"`-}--// UpdateUserGroupReq update user group request-type UpdateUserGroupReq struct {- // user group id- ID int64 `validate:"required" comment:"user group id" json:"id"`-}--// GetUserGroupListReq get user group list all request-type GetUserGroupListReq struct {-}--// GetUserGroupWithPageReq get user group list page request-type GetUserGroupWithPageReq struct {- // page- Page int `validate:"omitempty,min=1" form:"page"`- // page size- PageSize int `validate:"omitempty,min=1" form:"page_size"`-}--// GetUserGroupResp get user group response-type GetUserGroupResp struct {- // user group id- ID int64 `json:"id"`-}diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 98027870..88cc9b3c 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -195,7 +195,7 @@ type UserRegisterReq struct {func (u *UserRegisterReq) Check() (errField *validator.ErrorField, err error) {// TODO i18n- err = checker.PassWordCheck(8, 32, 0, u.Pass)+ err = checker.CheckPassword(8, 32, 0, u.Pass)if err != nil {return &validator.ErrorField{Key: "pass",@@ -214,7 +214,7 @@ type UserModifyPassWordRequest struct {func (u *UserModifyPassWordRequest) Check() (errField *validator.ErrorField, err error) {// TODO i18n- err = checker.PassWordCheck(8, 32, 0, u.Pass)+ err = checker.CheckPassword(8, 32, 0, u.Pass)if err != nil {return &validator.ErrorField{Key: "pass",@@ -272,7 +272,7 @@ type UserRePassWordRequest struct {func (u *UserRePassWordRequest) Check() (errField *validator.ErrorField, err error) {// TODO i18n- err = checker.PassWordCheck(8, 32, 0, u.Pass)+ err = checker.CheckPassword(8, 32, 0, u.Pass)if err != nil {return &validator.ErrorField{Key: "pass",diff --git a/internal/service/collection_common/collection.go b/internal/service/collection_common/collection.goindex 719f1b4b..0066bced 100644--- a/internal/service/collection_common/collection.go+++ b/internal/service/collection_common/collection.go@@ -21,7 +21,7 @@ type CollectionRepo interface {SearchList(ctx context.Context, search *entity.CollectionSearch) ([]*entity.Collection, int64, error)}-// CollectionService user service+// CollectionCommon user servicetype CollectionCommon struct {collectionRepo CollectionRepo}diff --git a/pkg/checker/password.go b/pkg/checker/password.goindex 33e4e3da..6c1bd6e6 100644--- a/pkg/checker/password.go+++ b/pkg/checker/password.go@@ -13,13 +13,12 @@ const (LevelS)-/*- * minLength: Specifies the minimum length of a password- * maxLength:Specifies the maximum length of a password- * minLevel:Specifies the minimum strength level required for passwords- * pwd:Text passwords- */-func PassWordCheck(minLength, maxLength, minLevel int, pwd string) error {+// CheckPassword+// minLength: Specifies the minimum length of a password+// maxLength:Specifies the maximum length of a password+// minLevel:Specifies the minimum strength level required for passwords+// pwd:Text passwords+func CheckPassword(minLength, maxLength, minLevel int, pwd string) error {// First check whether the password length is within the rangeif len(pwd) < minLength {return fmt.Errorf("BAD PASSWORD: The password is shorter than %d characters", minLength)diff --git a/pkg/dir/dir.go b/pkg/dir/dir.goindex 2a4d3519..5be4f8ec 100644--- a/pkg/dir/dir.go+++ b/pkg/dir/dir.go@@ -2,6 +2,7 @@ package dirimport "os"+// CreatePathIsNotExist create path is not existsfunc CreatePathIsNotExist(path string) (bool, error) {_, err := os.Stat(path)if err == nil {@@ -18,6 +19,7 @@ func CreatePathIsNotExist(path string) (bool, error) {return false, err}+// CheckPathExist path if existfunc CheckPathExist(path string) bool {_, err := os.Stat(path)if err == nil {diff --git a/pkg/encrypt/encrypt.go b/pkg/encrypt/encrypt.godeleted file mode 100644index 5d658e64..00000000--- a/pkg/encrypt/encrypt.go+++ /dev/null@@ -1,82 +0,0 @@-package encrypt--import (- "crypto/aes"- "crypto/cipher"- "crypto/rand"- "encoding/base64"- "fmt"- "io"- "net/url"-)--// StringEncrypt-func StringEncrypt(message, key string) (encoded string, err error) {- //Create byte array from the input string- plainText := []byte(message)-- //Create a new AES cipher using the key- block, err := aes.NewCipher([]byte(key))-- //IF NewCipher failed, exit:- if err != nil {- return- }-- //Make the cipher text a byte array of size BlockSize + the length of the message- cipherText := make([]byte, aes.BlockSize+len(plainText))-- //iv is the ciphertext up to the blocksize (16)- iv := cipherText[:aes.BlockSize]- if _, err = io.ReadFull(rand.Reader, iv); err != nil {- return- }-- //Encrypt the data:- stream := cipher.NewCFBEncrypter(block, iv)- stream.XORKeyStream(cipherText[aes.BlockSize:], plainText)-- //Return string encoded in base64- return base64.RawStdEncoding.EncodeToString(cipherText), err-}--// StringDecrypt-func StringDecrypt(secure, key string) (decoded string, err error) {- //Remove base64 encoding:- cipherText, err := base64.RawStdEncoding.DecodeString(secure)-- //IF DecodeString failed, exit:- if err != nil {- return- }-- //Create a new AES cipher with the key and encrypted message- block, err := aes.NewCipher([]byte(key))-- //IF NewCipher failed, exit:- if err != nil {- return- }-- //IF the length of the cipherText is less than 16 Bytes:- if len(cipherText) < aes.BlockSize {- err = fmt.Errorf("ciphertext block size is too short")- return- }-- iv := cipherText[:aes.BlockSize]- cipherText = cipherText[aes.BlockSize:]-- //Decrypt the message- stream := cipher.NewCFBDecrypter(block, iv)- stream.XORKeyStream(cipherText, cipherText)-- return string(cipherText), err-}--func StringUrlEnCode(str string) string {- return url.QueryEscape(str)-}-func StringUrlDeCode(str string) (string, error) {- return url.QueryUnescape(str)-}