Skip to content

Commit c0628e7

Browse files
committed
Refactor mapping process
1 parent 549e3fe commit c0628e7

File tree

14 files changed

+339
-210
lines changed

14 files changed

+339
-210
lines changed

advanced/examples.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package advanced
2+
3+
import (
4+
"github.com/devlights/try-golang/advanced/async"
5+
"github.com/devlights/try-golang/advanced/closure"
6+
"github.com/devlights/try-golang/advanced/crypto"
7+
"github.com/devlights/try-golang/advanced/generate"
8+
"github.com/devlights/try-golang/advanced/reflection"
9+
"github.com/devlights/try-golang/advanced/sets"
10+
"github.com/devlights/try-golang/advanced/xdgspec"
11+
"github.com/devlights/try-golang/interfaces"
12+
)
13+
14+
type (
15+
advancedExampleRegister struct{}
16+
)
17+
18+
// NewRegister は、advanced パッケージ用の lib.Register を返します.
19+
func NewRegister() interfaces.Register {
20+
r := new(advancedExampleRegister)
21+
return r
22+
}
23+
24+
func (r *advancedExampleRegister) Regist(m interfaces.SampleMapping) {
25+
m["async01"] = async.Async01
26+
m["async_producer_consumer"] = async.ProducerConsumer
27+
m["closure01"] = closure.Closure01
28+
m["crypto_bcrypt_password_hash"] = crypto.BcryptPasswordHash
29+
m["generate_generic_stack"] = generate.UseGenericStack
30+
m["generate_generic_queue"] = generate.UseGenericQueue
31+
m["reflection01"] = reflection.Reflection01
32+
m["set01"] = sets.Set01
33+
m["set02"] = sets.Set02
34+
m["set03"] = sets.Set03
35+
m["set04"] = sets.Set04
36+
m["set05"] = sets.Set05
37+
m["xdg_base_directory"] = xdgspec.XdgBaseDirectory
38+
m["xdg_user_directory"] = xdgspec.XdgUserDirectory
39+
m["xdg_file_operation"] = xdgspec.XdgFileOperation
40+
}

basic/examples.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package basic
2+
3+
import (
4+
"github.com/devlights/try-golang/advanced/sets"
5+
"github.com/devlights/try-golang/basic/array_"
6+
"github.com/devlights/try-golang/basic/builtin_"
7+
"github.com/devlights/try-golang/basic/comments"
8+
"github.com/devlights/try-golang/basic/constants"
9+
"github.com/devlights/try-golang/basic/defer_"
10+
"github.com/devlights/try-golang/basic/error_"
11+
"github.com/devlights/try-golang/basic/functions"
12+
"github.com/devlights/try-golang/basic/helloworld"
13+
"github.com/devlights/try-golang/basic/import_"
14+
"github.com/devlights/try-golang/basic/interface_"
15+
"github.com/devlights/try-golang/basic/io_"
16+
"github.com/devlights/try-golang/basic/iota_"
17+
"github.com/devlights/try-golang/basic/literals"
18+
"github.com/devlights/try-golang/basic/log_"
19+
"github.com/devlights/try-golang/basic/map_"
20+
"github.com/devlights/try-golang/basic/math_"
21+
"github.com/devlights/try-golang/basic/os_"
22+
"github.com/devlights/try-golang/basic/runtime_"
23+
"github.com/devlights/try-golang/basic/scope"
24+
"github.com/devlights/try-golang/basic/slice_"
25+
"github.com/devlights/try-golang/basic/sort_"
26+
"github.com/devlights/try-golang/basic/stdin"
27+
"github.com/devlights/try-golang/basic/stdout"
28+
"github.com/devlights/try-golang/basic/strconv_"
29+
"github.com/devlights/try-golang/basic/string_"
30+
"github.com/devlights/try-golang/basic/struct_"
31+
"github.com/devlights/try-golang/basic/time_"
32+
"github.com/devlights/try-golang/basic/type_"
33+
"github.com/devlights/try-golang/basic/unsafe_"
34+
"github.com/devlights/try-golang/basic/variables"
35+
"github.com/devlights/try-golang/interfaces"
36+
)
37+
38+
type (
39+
basicExampleRegister struct{}
40+
)
41+
42+
// NewRegister は、basic パッケージ用の lib.Register を返します.
43+
func NewRegister() interfaces.Register {
44+
r := new(basicExampleRegister)
45+
return r
46+
}
47+
48+
func (r *basicExampleRegister) Regist(m interfaces.SampleMapping) {
49+
m["builtin_print"] = builtin_.PrintFunc
50+
m["error_basic"] = error_.Basic
51+
m["error_sentinel"] = error_.Sentinel
52+
m["error_typeassertion"] = error_.TypeAssertion
53+
m["error_wrap_unwrap"] = error_.WrapAndUnwrap
54+
m["helloworld"] = helloworld.HelloWorld
55+
m["printf01"] = stdout.Printf01
56+
m["printf02"] = stdout.Printf02
57+
m["printf03"] = stdout.Printf03
58+
m["println01"] = stdout.Println01
59+
m["scanner01"] = stdin.Scanner01
60+
m["map_basic"] = map_.MapBasic
61+
m["map_for"] = map_.MapFor
62+
m["map_initialize"] = map_.MapInitialize
63+
m["map_delete"] = map_.MapDelete
64+
m["map_access"] = map_.MapAccess
65+
m["scope01"] = scope.Scope01
66+
m["import01"] = import_.Import01
67+
m["iota01"] = iota_.Iota01
68+
m["fileio01"] = io_.FileIo01
69+
m["fileio02"] = io_.FileIo02
70+
m["fileio03"] = io_.FileIo03
71+
m["fileio04"] = io_.FileIo04
72+
m["interface_basic"] = interface_.Basic
73+
m["interface_composition"] = interface_.Composition
74+
m["interface_ducktyping"] = interface_.DuckTyping
75+
m["os01"] = os_.Os01
76+
m["runtime01"] = runtime_.Runtime01
77+
m["struct01"] = struct_.Struct01
78+
m["struct02"] = struct_.Struct02
79+
m["struct03"] = struct_.Struct03
80+
m["struct04"] = struct_.Struct04
81+
m["struct_anonymous_struct"] = struct_.StructAnonymousStruct
82+
m["struct_empty_struct"] = struct_.EmptyStruct
83+
m["array01"] = array_.Array01
84+
m["slice01"] = slice_.Slice01
85+
m["slice02"] = slice_.Slice02
86+
m["slice03"] = slice_.Slice03
87+
m["slice04"] = slice_.Slice04
88+
m["slice05"] = slice_.Slice05
89+
m["slice_reverse"] = slice_.SliceReverse
90+
m["slice_append"] = slice_.SliceAppend
91+
m["slice_pointer"] = slice_.SlicePointer
92+
m["slice_copy"] = slice_.SliceCopy
93+
m["slice_clear"] = slice_.SliceClear
94+
m["comment01"] = comments.Comment01
95+
m["string_rune_rawstring"] = string_.StringRuneRawString
96+
m["string_to_runeslice"] = string_.StringToRuneSlice
97+
m["string_rune_byte_convert"] = string_.StringRuneByteConvert
98+
m["mapset01"] = sets.MapSet01
99+
m["defer01"] = defer_.Defer01
100+
m["var_statement_declare"] = variables.VarStatementDeclares
101+
m["package_scope_variable"] = variables.PackageScopeVariable
102+
m["short_assignment_statement"] = variables.ShortAssignmentStatement
103+
m["const_statement_declare"] = constants.ConstStatementDeclares
104+
m["function_one_return_value"] = functions.FunctionOneReturnValue
105+
m["function_multi_return_value"] = functions.FunctionMultiReturnValue
106+
m["function_named_return_value"] = functions.FunctionNamedReturnValue
107+
m["type01"] = type_.Type01
108+
m["minmax"] = math_.MinMax
109+
m["binary_int_literals"] = literals.BinaryIntLiterals
110+
m["octal_int_literals"] = literals.OctalIntLiterals
111+
m["hex_int_literals"] = literals.HexIntLiterals
112+
m["digit_separator"] = literals.DigitSeparators
113+
m["time_since"] = time_.TimeSince
114+
m["time_after"] = time_.TimeAfter
115+
m["time_unix_to_time"] = time_.TimeUnixToTime
116+
m["time_now"] = time_.TimeNow
117+
m["time_parse"] = time_.TimeParse
118+
m["hex_to_decimal_convert"] = strconv_.HexToDecimalConvert
119+
m["unsafe_sizeof"] = unsafe_.Sizeof
120+
m["log_flags"] = log_.Flags
121+
m["log_prefix"] = log_.Prefix
122+
m["log_sentry_basic"] = log_.SentryBasic
123+
m["log_sentry_goroutine_bad"] = log_.SentryGoroutineBad
124+
m["log_sentry_goroutine_good"] = log_.SentryGoroutineGood
125+
m["log_output"] = log_.Output
126+
m["log_new"] = log_.NewLogger
127+
m["sort_interface"] = sort_.SortInterface
128+
}

books/examples.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package books
2+
3+
import (
4+
"github.com/devlights/try-golang/interfaces"
5+
)
6+
7+
type (
8+
booksExampleRegister struct{}
9+
)
10+
11+
// NewRegister は、books パッケージ用の lib.Register を返します.
12+
func NewRegister() interfaces.Register {
13+
r := new(booksExampleRegister)
14+
return r
15+
}
16+
17+
//noinspection GoUnusedParameter
18+
func (r *booksExampleRegister) Regist(m interfaces.SampleMapping) {
19+
}

cmd/trygolang/errs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/devlights/try-golang/lib"
5+
"github.com/devlights/try-golang/interfaces"
66
)
77

88
type (
99
ExecError struct {
10-
Name lib.SampleKey
10+
Name interfaces.SampleKey
1111
Err error
1212
}
1313
)

cmd/trygolang/exec.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/devlights/try-golang/lib"
5+
"github.com/devlights/try-golang/interfaces"
66
)
77

88
type (
@@ -12,11 +12,11 @@ type (
1212

1313
ExecArgs struct {
1414
Target string
15-
Mapping lib.SampleMapping
15+
Mapping interfaces.SampleMapping
1616
}
1717
)
1818

19-
func NewExecArgs(target string, mapping lib.SampleMapping) *ExecArgs {
19+
func NewExecArgs(target string, mapping interfaces.SampleMapping) *ExecArgs {
2020
a := new(ExecArgs)
2121
a.Target = target
2222
a.Mapping = mapping
@@ -31,7 +31,7 @@ func NewExecCommand(args *ExecArgs) *ExecCommand {
3131

3232
func (c *ExecCommand) Run() error {
3333
var (
34-
target = lib.SampleKey(c.Args.Target)
34+
target = interfaces.SampleKey(c.Args.Target)
3535
mapping = c.Args.Mapping
3636
)
3737

cmd/trygolang/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"github.com/devlights/try-golang/interfaces"
56
"github.com/devlights/try-golang/lib"
67
"log"
78
"os"
@@ -10,14 +11,13 @@ import (
1011
func main() {
1112
var (
1213
args *Args
13-
mapping lib.SampleMapping
14+
mapping interfaces.SampleMapping
1415
)
1516

1617
args = NewArgs()
1718
args.Parse()
1819

19-
mapping = lib.NewSampleMapping()
20-
mapping.MakeMapping()
20+
mapping = lib.MakeMapping()
2121

2222
if args.ShowNames {
2323
printAllExampleNames(mapping)

cmd/trygolang/runloop.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"bufio"
55
"fmt"
6-
"github.com/devlights/try-golang/lib"
6+
"github.com/devlights/try-golang/interfaces"
77
"os"
88
"sort"
99
"strings"
@@ -16,11 +16,11 @@ type (
1616

1717
RunLoopArgs struct {
1818
MainArgs *Args
19-
Mapping lib.SampleMapping
19+
Mapping interfaces.SampleMapping
2020
}
2121
)
2222

23-
func NewRunLoopArgs(mainArgs *Args, mapping lib.SampleMapping) *RunLoopArgs {
23+
func NewRunLoopArgs(mainArgs *Args, mapping interfaces.SampleMapping) *RunLoopArgs {
2424
a := new(RunLoopArgs)
2525
a.MainArgs = mainArgs
2626
a.Mapping = mapping
@@ -110,7 +110,7 @@ func (c *RunLoopCommand) Run() error {
110110
return nil
111111
}
112112

113-
func (c *RunLoopCommand) exec(target string, mapping lib.SampleMapping) error {
113+
func (c *RunLoopCommand) exec(target string, mapping interfaces.SampleMapping) error {
114114
execArgs := NewExecArgs(target, mapping)
115115
execCmd := NewExecCommand(execArgs)
116116

@@ -121,7 +121,7 @@ func (c *RunLoopCommand) exec(target string, mapping lib.SampleMapping) error {
121121
return nil
122122
}
123123

124-
func (c *RunLoopCommand) makeCandidates(userInput string, mapping lib.SampleMapping) []string {
124+
func (c *RunLoopCommand) makeCandidates(userInput string, mapping interfaces.SampleMapping) []string {
125125
candidates := make([]string, 0, len(mapping))
126126
for k := range mapping {
127127
key := string(k)

cmd/trygolang/runonce.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

3-
import "github.com/devlights/try-golang/lib"
3+
import (
4+
"github.com/devlights/try-golang/interfaces"
5+
)
46

57
type (
68
RunOnceCommand struct {
@@ -12,7 +14,7 @@ type (
1214
}
1315
)
1416

15-
func NewRunOnceArgs(target string, mapping lib.SampleMapping) *RunOnceArgs {
17+
func NewRunOnceArgs(target string, mapping interfaces.SampleMapping) *RunOnceArgs {
1618
a := new(RunOnceArgs)
1719
a.Target = target
1820
a.Mapping = mapping

cmd/trygolang/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/devlights/try-golang/lib"
5+
"github.com/devlights/try-golang/interfaces"
66
"sort"
77
)
88

9-
func printAllExampleNames(mapping lib.SampleMapping) {
9+
func printAllExampleNames(mapping interfaces.SampleMapping) {
1010
names := make([]string, 0, len(mapping))
1111

1212
for k := range mapping {

effectivego/examples.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package effectivego
2+
3+
import (
4+
"github.com/devlights/try-golang/interfaces"
5+
)
6+
7+
type (
8+
effectivegoExampleRegister struct{}
9+
)
10+
11+
// NewRegister は、effectivego パッケージ用の lib.Register を返します.
12+
func NewRegister() interfaces.Register {
13+
r := new(effectivegoExampleRegister)
14+
return r
15+
}
16+
17+
func (r *effectivegoExampleRegister) Regist(m interfaces.SampleMapping) {
18+
m["effective_go_intro"] = Introduction
19+
m["effective_go_formatting"] = Formatting
20+
m["effective_go_comment"] = Commentary
21+
m["effective_go_names"] = Names
22+
m["effective_go_semicolon"] = Semicolons
23+
m["effective_go_control"] = ControlStructure
24+
m["effective_go_functions"] = Functions
25+
m["effective_go_defer"] = Defer
26+
m["effective_go_allocation_with_new"] = AllocationWithNew
27+
m["effective_go_constructors"] = Constructors
28+
m["effective_go_allocation_with_make"] = AllocationWithMake
29+
m["effective_go_arrays"] = Arrays
30+
m["effective_go_slices"] = Slices
31+
m["effective_go_two_dimentional_slices"] = TwoDimentionalSlices
32+
m["effective_go_maps"] = Maps
33+
m["effective_go_printing"] = Printing
34+
m["effective_go_append"] = Append
35+
m["effective_go_constants"] = Constants
36+
m["effective_go_methods"] = Methods
37+
}

0 commit comments

Comments
 (0)