prep for first renumber
This commit is contained in:
parent
bcf1c93cd3
commit
a8f3954cd5
@ -1,3 +1,11 @@
|
||||
## gbe-book
|
||||
|
||||
Go by Example book source.
|
||||
|
||||
|
||||
### Reordering
|
||||
|
||||
```bash
|
||||
$ mate tool/index.txt
|
||||
$ go run tool/reorder.go
|
||||
```
|
||||
|
96
tool/index.txt
Normal file
96
tool/index.txt
Normal file
@ -0,0 +1,96 @@
|
||||
hello-world
|
||||
values
|
||||
variables
|
||||
mutation
|
||||
literal
|
||||
constant
|
||||
reading-input
|
||||
for
|
||||
if-else
|
||||
case
|
||||
arrays
|
||||
sum
|
||||
range
|
||||
floats
|
||||
slices
|
||||
maps
|
||||
ok-guards
|
||||
nesting
|
||||
functions
|
||||
returns
|
||||
varargs
|
||||
closures
|
||||
recursion
|
||||
defer
|
||||
panic
|
||||
recover
|
||||
values
|
||||
pointers
|
||||
new
|
||||
structs
|
||||
fields
|
||||
methods
|
||||
embedding
|
||||
interfaces
|
||||
goroutines
|
||||
concurrency
|
||||
channels
|
||||
buffering
|
||||
directions
|
||||
synchronization
|
||||
select
|
||||
timeout
|
||||
string-fns
|
||||
bytes
|
||||
args
|
||||
burstable-rate-limiting
|
||||
dns
|
||||
elapsed
|
||||
email
|
||||
enumerable
|
||||
env
|
||||
epoch
|
||||
errors
|
||||
exec
|
||||
exits
|
||||
file-open
|
||||
file-read
|
||||
file-write
|
||||
flags
|
||||
http-client-basic
|
||||
http-client
|
||||
http-server-basic
|
||||
http-server-canonical-host
|
||||
http-server-graceful-shutdown
|
||||
http-server-log
|
||||
http-server-middleware
|
||||
http-server-routing
|
||||
http-server-static-dynamic
|
||||
http-server-static-select
|
||||
http-server-static
|
||||
http-server-status-code
|
||||
http-server
|
||||
https-client
|
||||
https-server
|
||||
json
|
||||
number-parsing
|
||||
postgres
|
||||
rand
|
||||
rate-limiting
|
||||
redis
|
||||
regexs
|
||||
scatter-gather
|
||||
sha1
|
||||
signals
|
||||
sort
|
||||
sortby
|
||||
spawn
|
||||
string-formatting
|
||||
tcp-client
|
||||
tcp-server
|
||||
tickers
|
||||
time
|
||||
timers
|
||||
url
|
||||
users
|
||||
worker-pool
|
44
tool/renumber.go
Normal file
44
tool/renumber.go
Normal file
@ -0,0 +1,44 @@
|
||||
// Renumber the .go content files according to the
|
||||
// order in index.txt.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// read names of source files
|
||||
sourceNames := make([]string, 0)
|
||||
sourceMap := make(map[string]string)
|
||||
fileInfos, dirErr := ioutil.ReadDir("./")
|
||||
if dirErr != nil { panic(dirErr) }
|
||||
baseTrimmer, _ := regexp.Compile("([0-9x]+-)|(.go)")
|
||||
for _, fi := range fileInfos {
|
||||
baseName := baseTrimmer.ReplaceAllString(fi.Name(), "")
|
||||
if baseName != ".git" && baseName != "tool" && baseName != "README.md" {
|
||||
sourceNames = append(sourceNames, baseName)
|
||||
sourceMap[baseName] = fi.Name()
|
||||
}
|
||||
}
|
||||
|
||||
// read names from index
|
||||
indexBytes, idxErr := ioutil.ReadFile("tool/index.txt")
|
||||
if idxErr != nil { panic (idxErr) }
|
||||
indexNames := strings.Split(string(indexBytes), "\n")
|
||||
|
||||
// sanity check two lists
|
||||
if len(sourceNames) != len(indexNames) {
|
||||
panic("mismatched names")
|
||||
}
|
||||
|
||||
// rename some stuff
|
||||
for index, indexName := range indexNames {
|
||||
oldName := sourceMap[indexName]
|
||||
newName := fmt.Sprintf("%d-%s.go", index+1, indexName)
|
||||
os.Rename(oldName, newName)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user