Skip to content

Commit

Permalink
rename package + some public to private
Browse files Browse the repository at this point in the history
  • Loading branch information
iLexN committed Oct 28, 2019
1 parent 2f8cd98 commit 2e232b6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 40 deletions.
4 changes: 2 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package go_hkid
package hkid

type patterNotMatchError struct {
}

func NewPatterNotMatchError() *patterNotMatchError {
func newPatterNotMatchError() *patterNotMatchError {
return &patterNotMatchError{}
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module "go_hkid"
module hkid

go 1.13
10 changes: 5 additions & 5 deletions helper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package go_hkid
package hkid

import (
"regexp"
Expand All @@ -12,7 +12,7 @@ func clearString(s string) string {
return newString
}

func getRemainder(hkid *Hkid) string {
func getRemainder(hkid *hkid) string {
charSum := getCharSum(hkid.part1)
hkidSum := calPart2Remainder(hkid.part2, charSum)

Expand Down Expand Up @@ -74,11 +74,11 @@ func getCharMap() map[string]int {
return idCharMap
}

func validatePatten(string string) (*Hkid, error) {
func validatePatten(string string) (*hkid, error) {
r, _ := regexp.Compile("^(?P<p1>\\D{1,2})(?P<p2>\\d{6})\\((?P<p3>[\\w{1}0-9aA])\\)$")
match := r.FindStringSubmatch(string)
if len(match) == 0 {
return NewHkidNil(), NewPatterNotMatchError()
return newHkidNil(), newPatterNotMatchError()
}
return NewHkid(match[1], match[2], match[3]), nil
return newHkid(match[1], match[2], match[3]), nil
}
10 changes: 5 additions & 5 deletions hkid.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package go_hkid
package hkid

func CheckString(string string) *HkidResult {
func CheckString(string string) *result {
hkid, e := validatePatten(string)
if e != nil {
return NewHkidResultWithValid(NewHkidNil(), false)
return NewHkidResultWithValid(newHkidNil(), false)
}

if getRemainder(hkid) == hkid.part3 {
Expand All @@ -13,7 +13,7 @@ func CheckString(string string) *HkidResult {
return NewHkidResultWithValid(hkid, false)
}

func CheckPart(part1 string, part2 string, part3 string) *HkidResult {
hkid := NewHkid(part1, part2, part3)
func CheckPart(part1 string, part2 string, part3 string) *result {
hkid := newHkid(part1, part2, part3)
return CheckString(hkid.Format())
}
8 changes: 0 additions & 8 deletions hkidInterface.go

This file was deleted.

18 changes: 9 additions & 9 deletions hkid_result.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package go_hkid
package hkid

type HkidResult struct {
hkid *Hkid
type result struct {
hkid *hkid
Valid bool
}

func (h *HkidResult) GetPart1() string {
func (h *result) GetPart1() string {
return h.hkid.GetPart1()
}

func (h *HkidResult) GetPart2() string {
func (h *result) GetPart2() string {
return h.hkid.GetPart2()
}

func (h *HkidResult) GetPart3() string {
func (h *result) GetPart3() string {
return h.hkid.GetPart3()
}

func (h *HkidResult) Format() string {
func (h *result) Format() string {
return h.hkid.Format()
}

func NewHkidResultWithValid(hkid *Hkid, valid bool) *HkidResult {
return &HkidResult{hkid: hkid, Valid: valid}
func NewHkidResultWithValid(hkid *hkid, valid bool) *result {
return &result{hkid: hkid, Valid: valid}
}
20 changes: 10 additions & 10 deletions hkid_value.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package go_hkid
package hkid

import "fmt"

type Hkid struct {
type hkid struct {
part1 string
part2 string
part3 string
}

func NewHkidNil() *Hkid {
return &Hkid{}
func newHkidNil() *hkid {
return &hkid{}
}

func NewHkid(part1 string, part2 string, part3 string) *Hkid {
return &Hkid{part1: clearString(part1), part2: part2, part3: clearString(part3)}
func newHkid(part1 string, part2 string, part3 string) *hkid {
return &hkid{part1: clearString(part1), part2: part2, part3: clearString(part3)}
}

func (hkid *Hkid) GetPart1() string {
func (hkid *hkid) GetPart1() string {
return hkid.part1
}

func (hkid *Hkid) GetPart2() string {
func (hkid *hkid) GetPart2() string {
return hkid.part2
}

func (hkid *Hkid) GetPart3() string {
func (hkid *hkid) GetPart3() string {
return hkid.part3
}

func (hkid *Hkid) Format() string {
func (hkid *hkid) Format() string {
return fmt.Sprintf("%s%s(%s)", hkid.part1, hkid.part2, hkid.part3)
}

0 comments on commit 2e232b6

Please sign in to comment.