From 4398976b5f6b6314fe8147a4dba39434aa2e4c31 Mon Sep 17 00:00:00 2001 From: Aleksey Kislitsa Date: Wed, 17 Mar 2021 11:22:25 +0300 Subject: [PATCH 1/4] Added Dockerfile and vim Go IDE --- .vimrc | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 25 +++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 .vimrc create mode 100644 Dockerfile diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..a81d4e9 --- /dev/null +++ b/.vimrc @@ -0,0 +1,93 @@ +syntax on +colo pablo + +" Flash screen instead of beep sound +set visualbell + +" Change how vim represents characters on the screen +set encoding=utf-8 + +" Set the encoding of files written +set fileencoding=utf-8 + + +autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 +autocmd Filetype go setlocal tabstop=4 shiftwidth=4 softtabstop=4 +" ts - show existing tab with 4 spaces width +" sw - when indenting with '>', use 4 spaces width +" sts - control and keys to match tabstop + +" Control all other files +set shiftwidth=4 + +set undofile " Maintain undo history between sessions +set undodir=~/.vim/undodir + +" Hardcore mode, disable arrow keys. +"noremap +"noremap +"noremap +"noremap + +filetype plugin indent on + +" Allow backspace to delete indentation and inserted text +" i.e. how it works in most programs +set backspace=indent,eol,start +" indent allow backspacing over autoindent +" eol allow backspacing over line breaks (join lines) +" start allow backspacing over the start of insert; CTRL-W and CTRL-U +" stop once at the start of insert. + +let g:go_version_warning = 0 + +" go-vim plugin specific commands +" Also run `goimports` on your current file on every save +" Might be be slow on large codebases, if so, just comment it out +let g:go_fmt_command = "goimports" + +" Status line types/signatures. +let g:go_auto_type_info = 1 + +"au filetype go inoremap . . + +" If you want to disable gofmt on save +" let g:go_fmt_autosave = 0 + + +" NERDTree plugin specific commands +:nnoremap :NERDTreeToggle +"autocmd vimenter * NERDTree + + +" air-line plugin specific commands +let g:airline_powerline_fonts = 1 + +if !exists('g:airline_symbols') + let g:airline_symbols = {} +endif + +" unicode symbols +let g:airline_left_sep = '»' +let g:airline_left_sep = '▶' +let g:airline_right_sep = '«' +let g:airline_right_sep = '◀' +let g:airline_symbols.linenr = '␊' +let g:airline_symbols.linenr = '␤' +let g:airline_symbols.linenr = '¶' +let g:airline_symbols.branch = '⎇' +let g:airline_symbols.paste = 'ρ' +let g:airline_symbols.paste = 'Þ' +let g:airline_symbols.paste = '∥' +let g:airline_symbols.whitespace = 'Ξ' + +" airline symbols +let g:airline_left_sep = '' +let g:airline_left_alt_sep = '' +let g:airline_right_sep = '' +let g:airline_right_alt_sep = '' +let g:airline_symbols.branch = '' +let g:airline_symbols.readonly = '' +let g:airline_symbols.linenr = '' + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c8c0c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.9.2 + +#RUN apt update -y && apt install sudo -y +RUN apt update -y && apt install sudo git vim -y +RUN wget https://github.com/Masterminds/glide/releases/download/v0.13.3/glide-v0.13.3-linux-amd64.tar.gz -O /tmp/glide.tar.gz && \ +tar -C /tmp -xzf /tmp/glide.tar.gz && cp /tmp/linux-amd64/glide /usr/local/bin + +# Create non-root user +RUN useradd -m dev && \ + adduser dev sudo && \ + echo "dev:dev" | chpasswd + +# Initilise base user +USER dev +WORKDIR /home/dev +ENV HOME /home/dev +ENV PATH=/home/dev/go/bin:$PATH +ENV GOPATH=/home/dev/go +ENV GOROOT=/usr/local/go +RUN go get golang.org/x/tools/cmd/goimports && \ +git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go && \ +git clone https://github.com/scrooloose/nerdtree.git ~/.vim/pack/dist/start/nerdtree && \ +git clone https://github.com/vim-airline/vim-airline ~/.vim/pack/dist/start/vim-airline && \ +git clone https://github.com/tpope/vim-fugitive.git ~/.vim/pack/dist/start/vim-fugitive +COPY .vimrc /home/dev/.vimrc From 3a69865abdfc8455eabe2493a89baff466856aa6 Mon Sep 17 00:00:00 2001 From: Aleksey Kislitsa Date: Wed, 17 Mar 2021 12:59:47 +0300 Subject: [PATCH 2/4] Updated up to go1.15 and added go-docker-dev ide --- .dockerignore | 2 + .vimrc | 93 ------ .../ch01-pure-fp/01_oop/.gitignore | 17 -- .../ch01-pure-fp/01_oop/main.go | 22 +- .../01_oop/src/github.com/go-delve/delve | 1 + Dockerfile | 68 +++-- fs/home/dev/.profile | 15 + fs/home/dev/.vim/colors/molokai.vim | 282 ++++++++++++++++++ fs/home/dev/.vimrc | 108 +++++++ 9 files changed, 467 insertions(+), 141 deletions(-) create mode 100644 .dockerignore delete mode 100644 .vimrc delete mode 100644 1-functional-fundamentals/ch01-pure-fp/01_oop/.gitignore create mode 160000 1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve create mode 100644 fs/home/dev/.profile create mode 100644 fs/home/dev/.vim/colors/molokai.vim create mode 100644 fs/home/dev/.vimrc diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4ace159 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!fs/ diff --git a/.vimrc b/.vimrc deleted file mode 100644 index a81d4e9..0000000 --- a/.vimrc +++ /dev/null @@ -1,93 +0,0 @@ -syntax on -colo pablo - -" Flash screen instead of beep sound -set visualbell - -" Change how vim represents characters on the screen -set encoding=utf-8 - -" Set the encoding of files written -set fileencoding=utf-8 - - -autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 -autocmd Filetype go setlocal tabstop=4 shiftwidth=4 softtabstop=4 -" ts - show existing tab with 4 spaces width -" sw - when indenting with '>', use 4 spaces width -" sts - control and keys to match tabstop - -" Control all other files -set shiftwidth=4 - -set undofile " Maintain undo history between sessions -set undodir=~/.vim/undodir - -" Hardcore mode, disable arrow keys. -"noremap -"noremap -"noremap -"noremap - -filetype plugin indent on - -" Allow backspace to delete indentation and inserted text -" i.e. how it works in most programs -set backspace=indent,eol,start -" indent allow backspacing over autoindent -" eol allow backspacing over line breaks (join lines) -" start allow backspacing over the start of insert; CTRL-W and CTRL-U -" stop once at the start of insert. - -let g:go_version_warning = 0 - -" go-vim plugin specific commands -" Also run `goimports` on your current file on every save -" Might be be slow on large codebases, if so, just comment it out -let g:go_fmt_command = "goimports" - -" Status line types/signatures. -let g:go_auto_type_info = 1 - -"au filetype go inoremap . . - -" If you want to disable gofmt on save -" let g:go_fmt_autosave = 0 - - -" NERDTree plugin specific commands -:nnoremap :NERDTreeToggle -"autocmd vimenter * NERDTree - - -" air-line plugin specific commands -let g:airline_powerline_fonts = 1 - -if !exists('g:airline_symbols') - let g:airline_symbols = {} -endif - -" unicode symbols -let g:airline_left_sep = '»' -let g:airline_left_sep = '▶' -let g:airline_right_sep = '«' -let g:airline_right_sep = '◀' -let g:airline_symbols.linenr = '␊' -let g:airline_symbols.linenr = '␤' -let g:airline_symbols.linenr = '¶' -let g:airline_symbols.branch = '⎇' -let g:airline_symbols.paste = 'ρ' -let g:airline_symbols.paste = 'Þ' -let g:airline_symbols.paste = '∥' -let g:airline_symbols.whitespace = 'Ξ' - -" airline symbols -let g:airline_left_sep = '' -let g:airline_left_alt_sep = '' -let g:airline_right_sep = '' -let g:airline_right_alt_sep = '' -let g:airline_symbols.branch = '' -let g:airline_symbols.readonly = '' -let g:airline_symbols.linenr = '' - - diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/.gitignore b/1-functional-fundamentals/ch01-pure-fp/01_oop/.gitignore deleted file mode 100644 index 11de31c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# Binaries for programs and plugins -*.exe -*.dll -*.so -*.dylib - -# Test binary, build with ? _/Users/lex/dev/01_oop [no test files] -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ - -# Temporary backup file created by sed in prune-project alias -main.go-e diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go b/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go index 7029698..da5506b 100644 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go +++ b/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go @@ -1,19 +1,19 @@ package main import ( - "oop" - "fmt" + "fmt" + "oop" ) func main() { - oop.MyCars.Add(oop.Car{"IS250"}) - oop.MyCars.Add(oop.Car{"Accord"}) - oop.MyCars.Add(oop.Car{"Highlander"}) + oop.MyCars.Add(oop.Car{"IS250"}) + oop.MyCars.Add(oop.Car{"Accord"}) + oop.MyCars.Add(oop.Car{"Highlander"}) - car, err := oop.MyCars.Find("Highlander") - if err != nil { - fmt.Printf("ERROR: %+v", err) - } else { - fmt.Printf("Found %+v", car) - } + car, err := oop.MyCars.Find("Highlander") + if err != nil { + fmt.Printf("ERROR: %+v", err) + } else { + fmt.Printf("Found %+v", car) + } } diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve b/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve new file mode 160000 index 0000000..333e84a --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve @@ -0,0 +1 @@ +Subproject commit 333e84a0cb209a9ec762b753cbd4ecbc679104d4 diff --git a/Dockerfile b/Dockerfile index 6c8c0c2..e88c0d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,53 @@ -FROM golang:1.9.2 +FROM golang:1.15 +MAINTAINER Michele Bertasi +MAINTAINER Aleksey Kislitsa -#RUN apt update -y && apt install sudo -y -RUN apt update -y && apt install sudo git vim -y -RUN wget https://github.com/Masterminds/glide/releases/download/v0.13.3/glide-v0.13.3-linux-amd64.tar.gz -O /tmp/glide.tar.gz && \ -tar -C /tmp -xzf /tmp/glide.tar.gz && cp /tmp/linux-amd64/glide /usr/local/bin +ADD fs/ / -# Create non-root user -RUN useradd -m dev && \ - adduser dev sudo && \ - echo "dev:dev" | chpasswd +# install pagkages +RUN apt-get update && \ + apt-get install -y ncurses-dev libtolua-dev exuberant-ctags gdb && \ + ln -s /usr/include/lua5.2/ /usr/include/lua && \ + ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/lib/liblua.so && \ +# cleanup + apt-get clean && rm -rf /var/lib/apt/lists/* + +# build and install vim +RUN cd /tmp && \ + git clone --depth 1 https://github.com/vim/vim.git && \ + cd vim && \ + ./configure --with-features=huge --enable-luainterp \ + --enable-gui=no --without-x --prefix=/usr && \ + make VIMRUNTIMEDIR=/usr/share/vim/vim82 && \ + make install && \ +# cleanup + rm -rf /tmp/* /var/tmp/* + +# get go tools +RUN go get golang.org/x/tools/cmd/godoc && \ + go get github.com/nsf/gocode && \ + go get golang.org/x/tools/cmd/goimports && \ + go get github.com/rogpeppe/godef && \ + go get golang.org/x/tools/cmd/gorename && \ + go get golang.org/x/lint/golint && \ + go get github.com/kisielk/errcheck && \ + go get github.com/jstemmer/gotags && \ + go get github.com/tools/godep && \ + GO111MODULE=on go get golang.org/x/tools/gopls@latest && \ + mv /go/bin/* /usr/local/go/bin && \ +# cleanup + rm -rf /go/src/* /go/pkg + +# add dev user +RUN adduser dev --disabled-password --gecos "" && \ + echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers && \ + chown -R dev:dev /home/dev /go -# Initilise base user USER dev -WORKDIR /home/dev ENV HOME /home/dev -ENV PATH=/home/dev/go/bin:$PATH -ENV GOPATH=/home/dev/go -ENV GOROOT=/usr/local/go -RUN go get golang.org/x/tools/cmd/goimports && \ -git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go && \ -git clone https://github.com/scrooloose/nerdtree.git ~/.vim/pack/dist/start/nerdtree && \ -git clone https://github.com/vim-airline/vim-airline ~/.vim/pack/dist/start/vim-airline && \ -git clone https://github.com/tpope/vim-fugitive.git ~/.vim/pack/dist/start/vim-fugitive -COPY .vimrc /home/dev/.vimrc +WORKDIR /home/dev + +# install vim plugins +RUN curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim && \ + vim +PlugInstall +qall diff --git a/fs/home/dev/.profile b/fs/home/dev/.profile new file mode 100644 index 0000000..a71ea74 --- /dev/null +++ b/fs/home/dev/.profile @@ -0,0 +1,15 @@ +# ~/.profile: executed by Bourne-compatible login shells. + +if [ "$BASH" ]; then + if [ -f ~/.bashrc ]; then + . ~/.bashrc + fi +fi + +if [ -e /usr/share/terminfo/x/xterm-256color ]; then + export TERM='xterm-256color' +else + export TERM='xterm-color' +fi + +mesg n diff --git a/fs/home/dev/.vim/colors/molokai.vim b/fs/home/dev/.vim/colors/molokai.vim new file mode 100644 index 0000000..7b71956 --- /dev/null +++ b/fs/home/dev/.vim/colors/molokai.vim @@ -0,0 +1,282 @@ +" Vim color file +" Converted from Textmate theme Monokai using Coloration v0.3.2 (http://github.com/sickill/coloration) + +set background=dark +highlight clear + +if exists("syntax_on") + syntax reset +endif + + +set t_Co=256 + +let g:colors_name="molokai" + +if exists("g:molokai_original") + let s:molokai_original = g:molokai_original +else + let s:molokai_original = 0 +endif + +hi Boolean guifg=#AE81FF +hi Character guifg=#E6DB74 +hi Number guifg=#AE81FF +hi String guifg=#E6DB74 +hi Conditional guifg=#F92672 gui=bold +hi Constant guifg=#AE81FF gui=bold +hi Cursor guifg=#000000 guibg=#F8F8F0 +hi iCursor guifg=#000000 guibg=#F8F8F0 +hi Debug guifg=#BCA3A3 gui=bold +hi Define guifg=#66D9EF +hi Delimiter guifg=#8F8F8F +hi DiffAdd guibg=#13354A +hi DiffChange guifg=#89807D guibg=#4C4745 +hi DiffDelete guifg=#960050 guibg=#1E0010 +hi DiffText guibg=#4C4745 gui=italic,bold + +hi Directory guifg=#A6E22E gui=bold +hi Error guifg=#E6DB74 guibg=#1E0010 +hi ErrorMsg guifg=#F92672 guibg=#232526 gui=bold +hi Exception guifg=#A6E22E gui=bold +hi Float guifg=#AE81FF +hi FoldColumn guifg=#465457 guibg=#000000 +hi Folded guifg=#465457 guibg=#000000 +hi Function guifg=#A6E22E +hi Identifier guifg=#FD971F +hi Ignore guifg=#808080 guibg=bg +hi IncSearch guifg=#C4BE89 guibg=#000000 + +hi Keyword guifg=#F92672 gui=bold +hi Label guifg=#E6DB74 gui=none +hi Macro guifg=#C4BE89 gui=italic +hi SpecialKey guifg=#66D9EF gui=italic + +hi MatchParen guifg=#000000 guibg=#FD971F gui=bold +hi ModeMsg guifg=#E6DB74 +hi MoreMsg guifg=#E6DB74 +hi Operator guifg=#F92672 + +" complete menu +hi Pmenu guifg=#66D9EF guibg=#000000 +hi PmenuSel guibg=#808080 +hi PmenuSbar guibg=#080808 +hi PmenuThumb guifg=#66D9EF + +hi PreCondit guifg=#A6E22E gui=bold +hi PreProc guifg=#A6E22E +hi Question guifg=#66D9EF +hi Repeat guifg=#F92672 gui=bold +hi Search guifg=#000000 guibg=#FFE792 +" marks +hi SignColumn guifg=#A6E22E guibg=#232526 +hi SpecialChar guifg=#F92672 gui=bold +hi SpecialComment guifg=#7E8E91 gui=bold +hi Special guifg=#66D9EF guibg=bg gui=italic +if has("spell") + hi SpellBad guisp=#FF0000 gui=undercurl + hi SpellCap guisp=#7070F0 gui=undercurl + hi SpellLocal guisp=#70F0F0 gui=undercurl + hi SpellRare guisp=#FFFFFF gui=undercurl +endif +hi Statement guifg=#F92672 gui=bold +hi StatusLine guifg=#455354 guibg=fg +hi StatusLineNC guifg=#808080 guibg=#080808 +hi StorageClass guifg=#FD971F gui=italic +hi Structure guifg=#66D9EF +hi Tag guifg=#F92672 gui=italic +hi Title guifg=#ef5939 +hi Todo guifg=#FFFFFF guibg=bg gui=bold + +hi Typedef guifg=#66D9EF +hi Type guifg=#66D9EF gui=none +hi Underlined guifg=#808080 gui=underline + +hi VertSplit guifg=#808080 guibg=#080808 gui=bold +hi VisualNOS guibg=#403D3D +hi Visual guibg=#403D3D +hi WarningMsg guifg=#FFFFFF guibg=#333333 gui=bold +hi WildMenu guifg=#66D9EF guibg=#000000 + +"hi TabLineFill guifg=#1B1D1E guibg=#64645e +"hi TabLine guibg=#1B1D1E guifg=#64645e gui=none + +if s:molokai_original == 1 + hi Normal guifg=#F8F8F2 guibg=#272822 + hi Comment guifg=#75715E + hi CursorLine guibg=#3E3D32 + hi CursorLineNr guifg=#FD971F gui=none + hi CursorColumn guibg=#3E3D32 + hi ColorColumn guibg=#3B3A32 + hi LineNr guifg=#8F908A guibg=#272822 + hi NonText guifg=#75715E + hi SpecialKey guifg=#75715E +else + hi Normal guifg=#F8F8F2 guibg=#1B1D1E + hi Comment guifg=#7E8E91 + hi CursorLine guibg=#293739 + hi CursorLineNr guifg=#FD971F gui=none + hi CursorColumn guibg=#293739 + hi ColorColumn guibg=#232526 + hi LineNr guifg=#465457 guibg=#232526 + hi NonText guifg=#465457 + hi SpecialKey guifg=#465457 +end + +" +" Support for 256-color terminal +" +if &t_Co > 255 + if s:molokai_original == 1 + hi Normal ctermbg=234 + hi CursorLine ctermbg=235 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + else + hi Normal ctermfg=252 ctermbg=233 + hi CursorLine ctermbg=234 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + endif + hi Boolean ctermfg=135 + hi Character ctermfg=144 + hi Number ctermfg=135 + hi String ctermfg=144 + hi Conditional ctermfg=161 cterm=bold + hi Constant ctermfg=135 cterm=bold + hi Cursor ctermfg=16 ctermbg=253 + hi Debug ctermfg=225 cterm=bold + hi Define ctermfg=81 + hi Delimiter ctermfg=241 + + hi DiffAdd ctermbg=24 + hi DiffChange ctermfg=181 ctermbg=239 + hi DiffDelete ctermfg=162 ctermbg=53 + hi DiffText ctermbg=102 cterm=bold + + hi Directory ctermfg=118 cterm=bold + hi Error ctermfg=219 ctermbg=89 + hi ErrorMsg ctermfg=199 ctermbg=16 cterm=bold + hi Exception ctermfg=118 cterm=bold + hi Float ctermfg=135 + hi FoldColumn ctermfg=67 ctermbg=16 + hi Folded ctermfg=67 ctermbg=16 + hi Function ctermfg=118 + hi Identifier ctermfg=208 cterm=none + hi Ignore ctermfg=244 ctermbg=232 + hi IncSearch ctermfg=193 ctermbg=16 + + hi keyword ctermfg=161 cterm=bold + hi Label ctermfg=229 cterm=none + hi Macro ctermfg=193 + hi SpecialKey ctermfg=81 + + hi MatchParen ctermfg=233 ctermbg=208 cterm=bold + hi ModeMsg ctermfg=229 + hi MoreMsg ctermfg=229 + hi Operator ctermfg=161 + + " complete menu + hi Pmenu ctermfg=81 ctermbg=16 + hi PmenuSel ctermfg=255 ctermbg=242 + hi PmenuSbar ctermbg=232 + hi PmenuThumb ctermfg=81 + + hi PreCondit ctermfg=118 cterm=bold + hi PreProc ctermfg=118 + hi Question ctermfg=81 + hi Repeat ctermfg=161 cterm=bold + hi Search ctermfg=0 ctermbg=222 cterm=NONE + + " marks column + hi SignColumn ctermfg=118 ctermbg=235 + hi SpecialChar ctermfg=161 cterm=bold + hi SpecialComment ctermfg=245 cterm=bold + hi Special ctermfg=81 + if has("spell") + hi SpellBad ctermbg=52 + hi SpellCap ctermbg=17 + hi SpellLocal ctermbg=17 + hi SpellRare ctermfg=none ctermbg=none cterm=reverse + endif + hi Statement ctermfg=161 cterm=bold + hi StatusLine ctermfg=238 ctermbg=253 + hi StatusLineNC ctermfg=244 ctermbg=232 + hi StorageClass ctermfg=208 + hi Structure ctermfg=81 + hi Tag ctermfg=161 + hi Title ctermfg=166 + hi Todo ctermfg=231 ctermbg=232 cterm=bold + + hi Typedef ctermfg=81 + hi Type ctermfg=81 cterm=none + hi Underlined ctermfg=244 cterm=underline + + hi VertSplit ctermfg=244 ctermbg=232 cterm=bold + hi VisualNOS ctermbg=238 + hi Visual ctermbg=235 + hi WarningMsg ctermfg=231 ctermbg=238 cterm=bold + hi WildMenu ctermfg=81 ctermbg=16 + + hi Comment ctermfg=59 + hi CursorColumn ctermbg=236 + hi ColorColumn ctermbg=236 + hi LineNr ctermfg=250 ctermbg=236 + hi NonText ctermfg=59 + + hi SpecialKey ctermfg=59 + + if exists("g:rehash256") && g:rehash256 == 1 + hi Normal ctermfg=252 ctermbg=234 + hi CursorLine ctermbg=236 cterm=none + hi CursorLineNr ctermfg=208 cterm=none + + hi Boolean ctermfg=141 + hi Character ctermfg=222 + hi Number ctermfg=141 + hi String ctermfg=222 + hi Conditional ctermfg=197 cterm=bold + hi Constant ctermfg=141 cterm=bold + + hi DiffDelete ctermfg=125 ctermbg=233 + + hi Directory ctermfg=154 cterm=bold + hi Error ctermfg=222 ctermbg=233 + hi Exception ctermfg=154 cterm=bold + hi Float ctermfg=141 + hi Function ctermfg=154 + hi Identifier ctermfg=208 + + hi Keyword ctermfg=197 cterm=bold + hi Operator ctermfg=197 + hi PreCondit ctermfg=154 cterm=bold + hi PreProc ctermfg=154 + hi Repeat ctermfg=197 cterm=bold + + hi Statement ctermfg=197 cterm=bold + hi Tag ctermfg=197 + hi Title ctermfg=203 + hi Visual ctermbg=238 + + hi Comment ctermfg=244 + hi LineNr ctermfg=239 ctermbg=235 + hi NonText ctermfg=239 + hi SpecialKey ctermfg=239 + endif +end + +hi Visual ctermbg=238 +hi Cursor ctermfg=235 ctermbg=231 cterm=NONE guifg=#272822 guibg=#f8f8f0 gui=NONE +hi CursorLine ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE +hi CursorColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE +hi ColorColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE +hi LineNr ctermfg=102 ctermbg=237 cterm=NONE guifg=#90908a guibg=#3c3d37 gui=NONE +hi VertSplit ctermfg=241 ctermbg=241 cterm=NONE guifg=#64645e guibg=#64645e gui=NONE +hi StatusLine ctermfg=231 ctermbg=241 cterm=bold guifg=#f8f8f2 guibg=#64645e gui=bold +hi StatusLineNC ctermfg=231 ctermbg=241 cterm=NONE guifg=#f8f8f2 guibg=#64645e gui=NONE +hi PmenuSel ctermfg=232 ctermbg=130 +hi Directory ctermfg=141 ctermbg=NONE cterm=NONE guifg=#ae81ff guibg=NONE gui=NONE +hi Folded ctermfg=242 ctermbg=235 cterm=NONE guifg=#75715e guibg=#272822 gui=NONE +hi SignColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE +hi Normal ctermfg=231 ctermbg=235 cterm=NONE guifg=#f8f8f2 guibg=#272822 gui=NONE +hi TabLine ctermbg=0 guifg=#75715E cterm=NONE guibg=#64645e gui=NONE +hi TabLineFill ctermbg=0 guifg=fg cterm=NONE guibg=#64645e gui=NONE +hi TabLineSel ctermbg=8 cterm=NONE gui=NONE diff --git a/fs/home/dev/.vimrc b/fs/home/dev/.vimrc new file mode 100644 index 0000000..a8fe361 --- /dev/null +++ b/fs/home/dev/.vimrc @@ -0,0 +1,108 @@ +set nocompatible " be iMproved + +call plug#begin() + +" custom plugins +Plug 'fatih/vim-go' +Plug 'majutsushi/tagbar' +Plug 'shougo/neocomplete.vim' +Plug 'scrooloose/nerdtree' +Plug 'bling/vim-airline' +Plug 'tpope/vim-fugitive' +Plug 'jistr/vim-nerdtree-tabs' +Plug 'mbbill/undotree' +Plug 'Lokaltog/vim-easymotion' +Plug 'scrooloose/nerdcommenter' + +" all of your Plugins must be added before the following line +call plug#end() " required + +" general customizations +syntax on +set ts=4 +set sw=4 +set number +set cursorline +set scrolloff=999 +set encoding=utf-8 +colorscheme molokai + +" plugin customizations +" neocomplete +let g:neocomplete#enable_at_startup = 1 + +" vim go +" disable open browser after posting snippet +let g:go_play_open_browser = 0 +" enable goimports +let g:go_fmt_command = "goimports" +" enable additional highlighting +let g:go_highlight_functions = 1 +let g:go_highlight_methods = 1 +let g:go_highlight_structs = 1 + +" vim-airline +set laststatus=2 +let g:bufferline_echo = 0 +let g:airline#extensions#tabline#enabled = 1 +let g:airline_theme = 'dark' + +" tagbar +let g:tagbar_type_go = { + \ 'ctagstype' : 'go', + \ 'kinds' : [ + \ 'p:package', + \ 'i:imports:1', + \ 'c:constants', + \ 'v:variables', + \ 't:types', + \ 'n:interfaces', + \ 'w:fields', + \ 'e:embedded', + \ 'm:methods', + \ 'r:constructor', + \ 'f:functions' + \ ], + \ 'sro' : '.', + \ 'kind2scope' : { + \ 't' : 'ctype', + \ 'n' : 'ntype' + \ }, + \ 'scope2kind' : { + \ 'ctype' : 't', + \ 'ntype' : 'n' + \ }, + \ 'ctagsbin' : 'gotags', + \ 'ctagsargs' : '-sort -silent' +\ } + + +" shortcuts remap +nmap :tabnew +nmap :tabclose +nmap :UndotreeToggle +nmap :NERDTreeTabsToggle +nmap :TagbarToggle +nmap :tabprevious +nmap :tabnext + +" show a list of interfaces which is implemented by the type under your cursor +au FileType go nmap s (go-implements) +" show type info for the word under your cursor +au FileType go nmap gi (go-info) +" open the relevant Godoc for the word under the cursor +au FileType go nmap gd (go-doc) +au FileType go nmap gv (go-doc-vertical) +" run Go commands +au FileType go nmap r (go-run) +au FileType go nmap b (go-build) +au FileType go nmap t (go-test) +au FileType go nmap c (go-coverage) +au FileType go nmap i (go-install) +" open the definition/declaration in a new vertical, horizontal or tab for the +" word under your cursor +au FileType go nmap ds (go-def-split) +au FileType go nmap dv (go-def-vertical) +au FileType go nmap dt (go-def-tab) +" rename the identifier under the cursor to a new name +au FileType go nmap e (go-rename) From 83e5ec4019403a6e1ff149841b022d7154ba74b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kislitsa Date: Wed, 17 Mar 2021 14:03:10 +0300 Subject: [PATCH 3/4] Added go-env and go-ide for working with local packages(not from gitgub, just from local src folder) --- .dockerignore | 2 ++ Dockerfile | 2 ++ go-env | 3 +++ go-ide | 3 +++ 4 files changed, 10 insertions(+) create mode 100755 go-env create mode 100755 go-ide diff --git a/.dockerignore b/.dockerignore index 4ace159..2bad11d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ * !fs/ +!go-env +!go-ide diff --git a/Dockerfile b/Dockerfile index e88c0d4..a48f3fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ MAINTAINER Michele Bertasi MAINTAINER Aleksey Kislitsa ADD fs/ / +ADD go-env /usr/local/bin +ADD go-ide /usr/local/bin # install pagkages RUN apt-get update && \ diff --git a/go-env b/go-env new file mode 100755 index 0000000..579da86 --- /dev/null +++ b/go-env @@ -0,0 +1,3 @@ +#!/bin/sh + +GOPATH=$GOPATH:`pwd` go $* diff --git a/go-ide b/go-ide new file mode 100755 index 0000000..1d35317 --- /dev/null +++ b/go-ide @@ -0,0 +1,3 @@ +#!/bin/sh + +GOPATH=$GOPATH:`pwd` vim $* From 573460bb76008147bd6881893c35b70be183e0b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kislitsa Date: Wed, 18 May 2022 11:27:59 +0300 Subject: [PATCH 4/4] Source code was adopted for golang 1.18 --- .dockerignore | 1 + .../ch01-pure-fp/01_oop/go.mod | 3 + .../ch01-pure-fp/01_oop/init | 183 ----- .../ch01-pure-fp/01_oop/init-windows.sh | 23 - .../ch01-pure-fp/01_oop/main.go | 2 +- .../ch01-pure-fp/01_oop/{src => }/oop/cars.go | 0 .../01_oop/src/github.com/go-delve/delve | 1 - .../02_fib/{src => }/fibonacci/channel.go | 0 .../{src => }/fibonacci/channel_test.go | 0 .../{src => }/fibonacci/memoize.go_ORIG | 0 .../{src => }/fibonacci/memoize_test.go | 0 .../02_fib/{src => }/fibonacci/meomoize.go | 0 .../02_fib/{src => }/fibonacci/simple.go | 0 .../02_fib/{src => }/fibonacci/simple_test.go | 0 .../ch01-pure-fp/02_fib/go.mod | 3 + .../ch01-pure-fp/02_fib/init | 183 ----- .../ch01-pure-fp/02_fib/init-windows.sh | 21 - .../ch01-pure-fp/02_fib/main.go | 2 +- .../ch01-pure-fp/03_anonymous/go.mod | 3 + .../ch01-pure-fp/03_anonymous/init | 183 ----- .../ch01-pure-fp/03_anonymous/init-windows.sh | 21 - .../ch01-pure-fp/04_greeting/go.mod | 3 + .../ch01-pure-fp/04_greeting/init | 183 ----- .../ch01-pure-fp/04_greeting/init-windows.sh | 21 - .../ch01-pure-fp/05_sum/go.mod | 3 + .../ch01-pure-fp/05_sum/init | 183 ----- .../ch01-pure-fp/05_sum/init-windows.sh | 21 - .../ch01-pure-fp/05_sum/{src => }/sum/loop.go | 0 .../05_sum/{src => }/sum/loop_test.go | 0 .../05_sum/{src => }/sum/recursive.go | 0 .../05_sum/{src => }/sum/recursive_test.go | 0 .../05_sum/{src => }/sum/tailcall.go | 0 .../05_sum/{src => }/sum/tailcall_test.go | 0 .../ch01-pure-fp/06_curry/go.mod | 3 + .../ch01-pure-fp/06_curry/init | 183 ----- .../ch01-pure-fp/06_curry/init-windows.sh | 21 - .../ch02-collections/01_iterator/go.mod | 3 + .../ch02-collections/01_iterator/init | 183 ----- .../01_iterator/init-windows.sh | 21 - .../ch02-collections/02_chainlink/go.mod | 3 + .../ch02-collections/02_chainlink/init | 183 ----- .../02_chainlink/init-windows.sh | 21 - .../ch03-hof/01_cps/go.mod | 3 + .../ch03-hof/01_cps/init | 183 ----- .../ch03-hof/01_cps/init-windows.sh | 21 - .../ch03-hof/02_fcn_comp/go.mod | 3 + .../ch03-hof/02_fcn_comp/init | 183 ----- .../ch03-hof/02_fcn_comp/init-windows.sh | 21 - .../ch03-hof/03_hof/go.mod | 5 + .../ch03-hof/03_hof/go.sum | 2 + .../ch03-hof/03_hof/{src => }/hof/cars.go | 0 .../03_hof/{src => }/hof/generator.go | 0 .../ch03-hof/03_hof/{src => }/hof/restful.go | 0 .../ch03-hof/03_hof/{src => }/hof/types.go | 0 .../ch03-hof/03_hof/{src => }/hof/utils.go | 0 .../ch03-hof/03_hof/init | 183 ----- .../ch03-hof/03_hof/init-windows.sh | 21 - .../ch03-hof/03_hof/main.go | 2 +- .../ch03-hof/04_scoping/go.mod | 3 + .../ch03-hof/04_scoping/init | 183 ----- .../ch03-hof/04_scoping/init-windows.sh | 21 - .../ch03-hof/05_closure/go.mod | 3 + 2-design-patterns/ch04-solid/01_lambda/go.mod | 3 + 2-design-patterns/ch04-solid/01_lambda/init | 183 ----- .../ch04-solid/01_lambda/init-windows.sh | 21 - 2-design-patterns/ch04-solid/02_maybe/go.mod | 3 + 2-design-patterns/ch04-solid/02_maybe/init | 183 ----- .../ch04-solid/02_maybe/init-windows.sh | 21 - 2-design-patterns/ch04-solid/02_maybe/main.go | 2 +- .../02_maybe/{src => }/maybe/either.go | 0 .../02_maybe/{src => }/maybe/either_error.go | 0 .../02_maybe/{src => }/maybe/option.go | 0 .../02_maybe/{src => }/maybe/option_error.go | 0 .../02_maybe/{src => }/maybe/string_either.go | 0 .../02_maybe/{src => }/maybe/string_option.go | 0 .../ch04-solid/03_car/{src => }/car/car.go | 0 2-design-patterns/ch04-solid/03_car/go.mod | 3 + 2-design-patterns/ch04-solid/03_car/init | 183 ----- .../ch04-solid/03_car/init-windows.sh | 21 - 2-design-patterns/ch04-solid/03_car/main.go | 2 +- 2-design-patterns/ch04-solid/05_duck/go.mod | 3 + 2-design-patterns/ch04-solid/05_duck/init | 183 ----- .../ch04-solid/05_duck/init-windows.sh | 21 - 2-design-patterns/ch04-solid/06_misc/go.mod | 3 + .../ch05-decoration/01_reader_writer/go.mod | 3 + .../ch05-decoration/01_reader_writer/init | 183 ----- .../01_reader_writer/init-windows.sh | 21 - .../{src => }/decorator/decorator.go | 0 .../{src => }/decorator/requestor.go | 0 .../{src => }/decorator/simple_log.go | 0 .../{src => }/easy_metrics/metrics.go | 0 .../ch05-decoration/02_decorator/go.mod | 5 + .../ch05-decoration/02_decorator/go.sum | 2 + .../ch05-decoration/02_decorator/init | 183 ----- .../02_decorator/init-windows.sh | 21 - .../ch05-decoration/02_decorator/main.go | 4 +- .../01_dependency-rule-good/go.mod | 3 + .../01_dependency-rule-good/init | 183 ----- .../01_dependency-rule-good/init-windows.sh | 21 - .../01_dependency-rule-good/main.go | 2 +- .../packagea/featurea.go | 2 +- .../{src => }/packageb/featureb.go | 0 .../ch06-onion-arch/02_circulardep/go.mod | 3 + .../ch06-onion-arch/02_circulardep/init | 183 ----- .../02_circulardep/init-windows.sh | 21 - .../ch06-onion-arch/02_circulardep/main.go | 2 +- .../{src => }/packagea/featurea.go | 2 +- .../{src => }/packageb/featureb.go | 2 +- .../ch06-onion-arch/03_observer/go.mod | 3 + .../ch06-onion-arch/03_observer/init | 183 ----- .../03_observer/init-windows.sh | 21 - .../ch06-onion-arch/03_observer/main.go | 2 +- .../{src => }/observer/observer.go | 0 .../03_observer/{src => }/observer/subject.go | 0 .../04_onion/{src => }/domain/api.go | 0 .../04_onion/{src => }/domain/domain.go | 0 .../04_onion/{src => }/domain/file.go | 2 +- .../04_onion/{src => }/domain/log_file.go | 0 .../ch06-onion-arch/04_onion/go.mod | 32 + .../ch06-onion-arch/04_onion/go.sum | 645 ++++++++++++++++++ .../{src => }/infrastructure/gcphandler.go | 24 +- .../infrastructure_test/localhandler_test.go | 2 +- .../{src => }/infrastructure/localhandler.go | 12 +- .../ch06-onion-arch/04_onion/init | 183 ----- .../ch06-onion-arch/04_onion/init-windows.sh | 21 - .../{src => }/interfaces/gcpstorage.go | 10 +- .../{src => }/interfaces/impl.go_STOP | 0 .../interfaces_test/webservice_test.go | 25 +- .../{src => }/interfaces/localstorage.go | 0 .../{src => }/interfaces/webservice.go | 6 +- .../interfaces/webservice_helpers.go | 22 +- .../ch06-onion-arch/04_onion/main.go | 28 +- .../04_onion/{src => }/usecases/usecases.go | 4 +- .../04_onion/{src => }/utils/logger.go | 0 .../04_onion/{src => }/utils/options.go | 0 .../04_onion/{src => }/utils/utils.go | 0 .../{src => }/utils/utils_test/utils_test.go | 6 +- .../ch07-func-param/01_func_param/go.mod | 11 + .../ch07-func-param/01_func_param/go.sum | 14 + .../ch07-func-param/01_func_param/init | 183 ----- .../01_func_param/init-windows.sh | 21 - .../ch07-func-param/01_func_param/main.go | 16 +- .../01_func_param/{src => }/server/server.go | 0 .../{src => }/server/server_options.go | 5 +- .../01_func_param/{src => }/utils/logger.go | 0 .../01_func_param/{src => }/utils/options.go | 0 .../01_func_param/{src => }/utils/utils.go | 0 .../utils/utils_test/utils_test.go | 6 +- .../ch08-pipelining/01_imperative/go.mod | 3 + .../ch08-pipelining/01_imperative/init | 183 ----- .../01_imperative/init-windows.sh | 21 - .../ch08-pipelining/02_concurrent/go.mod | 3 + .../ch08-pipelining/02_concurrent/init | 183 ----- .../02_concurrent/init-windows.sh | 21 - .../ch08-pipelining/03_buffered/go.mod | 3 + .../ch08-pipelining/03_buffered/init | 183 ----- .../03_buffered/init-windows.sh | 21 - .../ch08-pipelining/04_buffered_cpus/go.mod | 3 + .../ch08-pipelining/04_buffered_cpus/init | 183 ----- .../04_buffered_cpus/init-windows.sh | 21 - .../ch08-pipelining/go.mod | 13 + .../ch08-pipelining/go.sum | 8 + .../{src => }/functor/clock.go | 0 .../01_clock_functor/go.mod | 3 + .../ch09-functor-monoid/01_clock_functor/init | 183 ----- .../01_clock_functor/init-windows.sh | 21 - .../01_clock_functor/main.go | 5 +- .../01_no_generics_nums/go.mod | 3 + .../{src => }/car/car_slice.go | 0 .../02_generics_cars/{src => }/car/types.go | 0 .../02_generics_cars/go.mod | 3 + .../ch09-functor-monoid/02_generics_cars/init | 183 ----- .../02_generics_cars/init-windows.sh | 21 - .../02_generics_cars/main.go | 2 +- .../03_generics_nums/go.mod | 3 + .../ch09-functor-monoid/03_generics_nums/init | 183 ----- .../03_generics_nums/init-windows.sh | 21 - .../03_generics_nums/main.go | 2 +- .../{src => }/num/complex128_slice.go | 0 .../{src => }/num/float64_slice.go | 0 .../{src => }/num/int32_slice.go | 0 .../{src => }/num/int8_slice.go | 0 .../03_generics_nums/{src => }/num/types.go | 0 .../03_generics_nums/{src => }/num/vars.go | 0 .../05_int_functor/{src => }/functor/ints.go | 0 .../ch09-functor-monoid/05_int_functor/go.mod | 3 + .../ch09-functor-monoid/05_int_functor/init | 183 ----- .../05_int_functor/init-windows.sh | 21 - .../05_int_functor/main.go | 2 +- .../06_compose/{src => }/compose/compose.go | 0 .../ch09-functor-monoid/06_compose/go.mod | 3 + .../ch09-functor-monoid/06_compose/init | 183 ----- .../06_compose/init-windows.sh | 21 - .../ch09-functor-monoid/06_compose/main.go | 2 +- .../{src => }/compose/compose.go | 0 .../ch09-functor-monoid/07_compose_gof/go.mod | 3 + .../ch09-functor-monoid/07_compose_gof/init | 183 ----- .../07_compose_gof/init-windows.sh | 21 - .../07_compose_gof/main.go | 2 +- .../{src => }/compose/compose.go | 0 .../ch09-functor-monoid/08_compose_fog/go.mod | 3 + .../ch09-functor-monoid/08_compose_fog/init | 183 ----- .../08_compose_fog/init-windows.sh | 21 - .../08_compose_fog/main.go | 2 +- .../{src => }/functor/clock.go | 0 .../09_clock_functor/go.mod | 3 + .../ch09-functor-monoid/09_clock_functor/init | 183 ----- .../09_clock_functor/init-windows.sh | 21 - .../09_clock_functor/main.go | 2 +- .../10_car_functor/{src => }/functor/car.go | 0 .../ch09-functor-monoid/10_car_functor/go.mod | 3 + .../ch09-functor-monoid/10_car_functor/init | 183 ----- .../10_car_functor/init-windows.sh | 21 - .../10_car_functor/main.go | 2 +- .../ch09-functor-monoid/11_monoid/go.mod | 3 + .../ch09-functor-monoid/11_monoid/init | 183 ----- .../11_monoid/init-windows.sh | 21 - .../ch09-functor-monoid/11_monoid/main.go | 2 +- .../11_monoid/{src => }/monoid/README.md | 0 .../11_monoid/{src => }/monoid/int_monoid.go | 0 .../{src => }/monoid/lineitem_monoid.go | 0 .../11_monoid/{src => }/monoid/name_monoid.go | 0 .../ch10-monads/01_car_steps/go.mod | 11 + .../ch10-monads/01_car_steps/go.sum | 14 + .../ch10-monads/01_car_steps/init | 183 ----- .../ch10-monads/01_car_steps/init-windows.sh | 21 - .../ch10-monads/01_car_steps/main.go | 27 +- .../01_car_steps/{src => }/utils/logger.go | 0 .../01_car_steps/{src => }/utils/options.go | 0 .../01_car_steps/{src => }/utils/utils.go | 0 .../utils/utils_test/utils_test.go | 6 +- .../{src => }/workflow/car_types.go | 0 .../01_car_steps/{src => }/workflow/monad.go | 0 .../{src => }/workflow/process_car_steps.go | 2 +- .../{src => }/workflow/toolbox.go | 0 .../ch10-monads/02_error_checker/go.mod | 3 + .../ch10-monads/02_error_checker/init | 183 ----- .../02_error_checker/init-windows.sh | 21 - .../ch10-monads/03_y_combinator/go.mod | 3 + .../ch10-monads/03_y_combinator/init | 183 ----- .../03_y_combinator/init-windows.sh | 21 - .../ch10-monads/04_i18n/go.mod | 12 + .../ch10-monads/04_i18n/go.sum | 12 + .../04_i18n/{src => }/i18n/errors.go | 0 4-purely-functional/ch10-monads/04_i18n/init | 183 ----- .../ch10-monads/04_i18n/init-windows.sh | 21 - .../ch10-monads/05_typeclasss/go.mod | 3 + .../ch10-monads/05_typeclasss/init | 183 ----- .../ch10-monads/05_typeclasss/init-windows.sh | 21 - .../ch10-monads/05_typeclasss/main.go | 30 +- .../{src => }/typeclass/equals.go | 0 .../05_typeclasss/{src => }/typeclass/sum.go | 0 .../01_essense_of_iterator/go.mod | 3 + .../01_essense_of_iterator/init | 183 ----- .../01_essense_of_iterator/init-windows.sh | 21 - .../ch11-category-theory/02_anonymous/go.mod | 3 + .../ch11-category-theory/03_lambda/go.mod | 3 + .../ch11-category-theory/04_lambda/go.mod | 3 + .../05_typeinferer/go.mod | 3 + 5-appendix/01_no-imports/go.mod | 3 + 5-appendix/01_no-imports/init | 183 ----- 5-appendix/01_no-imports/init-windows.sh | 21 - 5-appendix/01_no-imports/main.go | 3 +- .../01_no-imports}/packagea/featurea.go | 3 +- .../{src => }/packageb/featureb.go | 0 5-appendix/02_dependency-with-import/go.mod | 3 + 5-appendix/02_dependency-with-import/init | 183 ----- .../02_dependency-with-import/init-windows.sh | 21 - 5-appendix/02_dependency-with-import/main.go | 3 +- .../{src => }/packagea/featurea.go | 3 +- .../{src => }/packageb/featureb.go | 0 5-appendix/03_with-third-party-import/go.mod | 12 + 5-appendix/03_with-third-party-import/go.sum | 15 + 5-appendix/03_with-third-party-import/init | 183 ----- .../init-windows.sh | 21 - 5-appendix/03_with-third-party-import/main.go | 3 +- .../{src => }/packagea/featurea.go | 4 +- .../{src => }/packageb/featureb.go | 0 Dockerfile | 41 +- go-init | 7 + 280 files changed, 1118 insertions(+), 9570 deletions(-) create mode 100644 1-functional-fundamentals/ch01-pure-fp/01_oop/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/01_oop/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/01_oop/init-windows.sh rename 1-functional-fundamentals/ch01-pure-fp/01_oop/{src => }/oop/cars.go (100%) delete mode 160000 1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/channel.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/channel_test.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/memoize.go_ORIG (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/memoize_test.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/meomoize.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/simple.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/02_fib/{src => }/fibonacci/simple_test.go (100%) create mode 100644 1-functional-fundamentals/ch01-pure-fp/02_fib/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/02_fib/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/02_fib/init-windows.sh create mode 100644 1-functional-fundamentals/ch01-pure-fp/03_anonymous/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/03_anonymous/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/03_anonymous/init-windows.sh create mode 100644 1-functional-fundamentals/ch01-pure-fp/04_greeting/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/04_greeting/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/04_greeting/init-windows.sh create mode 100644 1-functional-fundamentals/ch01-pure-fp/05_sum/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/05_sum/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/05_sum/init-windows.sh rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/loop.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/loop_test.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/recursive.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/recursive_test.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/tailcall.go (100%) rename 1-functional-fundamentals/ch01-pure-fp/05_sum/{src => }/sum/tailcall_test.go (100%) create mode 100644 1-functional-fundamentals/ch01-pure-fp/06_curry/go.mod delete mode 100644 1-functional-fundamentals/ch01-pure-fp/06_curry/init delete mode 100755 1-functional-fundamentals/ch01-pure-fp/06_curry/init-windows.sh create mode 100644 1-functional-fundamentals/ch02-collections/01_iterator/go.mod delete mode 100644 1-functional-fundamentals/ch02-collections/01_iterator/init delete mode 100755 1-functional-fundamentals/ch02-collections/01_iterator/init-windows.sh create mode 100644 1-functional-fundamentals/ch02-collections/02_chainlink/go.mod delete mode 100755 1-functional-fundamentals/ch02-collections/02_chainlink/init delete mode 100755 1-functional-fundamentals/ch02-collections/02_chainlink/init-windows.sh create mode 100644 1-functional-fundamentals/ch03-hof/01_cps/go.mod delete mode 100644 1-functional-fundamentals/ch03-hof/01_cps/init delete mode 100755 1-functional-fundamentals/ch03-hof/01_cps/init-windows.sh create mode 100644 1-functional-fundamentals/ch03-hof/02_fcn_comp/go.mod delete mode 100644 1-functional-fundamentals/ch03-hof/02_fcn_comp/init delete mode 100755 1-functional-fundamentals/ch03-hof/02_fcn_comp/init-windows.sh create mode 100644 1-functional-fundamentals/ch03-hof/03_hof/go.mod create mode 100644 1-functional-fundamentals/ch03-hof/03_hof/go.sum rename 1-functional-fundamentals/ch03-hof/03_hof/{src => }/hof/cars.go (100%) rename 1-functional-fundamentals/ch03-hof/03_hof/{src => }/hof/generator.go (100%) rename 1-functional-fundamentals/ch03-hof/03_hof/{src => }/hof/restful.go (100%) rename 1-functional-fundamentals/ch03-hof/03_hof/{src => }/hof/types.go (100%) rename 1-functional-fundamentals/ch03-hof/03_hof/{src => }/hof/utils.go (100%) delete mode 100644 1-functional-fundamentals/ch03-hof/03_hof/init delete mode 100755 1-functional-fundamentals/ch03-hof/03_hof/init-windows.sh create mode 100644 1-functional-fundamentals/ch03-hof/04_scoping/go.mod delete mode 100644 1-functional-fundamentals/ch03-hof/04_scoping/init delete mode 100755 1-functional-fundamentals/ch03-hof/04_scoping/init-windows.sh create mode 100644 1-functional-fundamentals/ch03-hof/05_closure/go.mod create mode 100644 2-design-patterns/ch04-solid/01_lambda/go.mod delete mode 100644 2-design-patterns/ch04-solid/01_lambda/init delete mode 100755 2-design-patterns/ch04-solid/01_lambda/init-windows.sh create mode 100644 2-design-patterns/ch04-solid/02_maybe/go.mod delete mode 100644 2-design-patterns/ch04-solid/02_maybe/init delete mode 100755 2-design-patterns/ch04-solid/02_maybe/init-windows.sh rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/either.go (100%) rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/either_error.go (100%) rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/option.go (100%) rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/option_error.go (100%) rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/string_either.go (100%) rename 2-design-patterns/ch04-solid/02_maybe/{src => }/maybe/string_option.go (100%) rename 2-design-patterns/ch04-solid/03_car/{src => }/car/car.go (100%) create mode 100644 2-design-patterns/ch04-solid/03_car/go.mod delete mode 100644 2-design-patterns/ch04-solid/03_car/init delete mode 100755 2-design-patterns/ch04-solid/03_car/init-windows.sh create mode 100644 2-design-patterns/ch04-solid/05_duck/go.mod delete mode 100644 2-design-patterns/ch04-solid/05_duck/init delete mode 100755 2-design-patterns/ch04-solid/05_duck/init-windows.sh create mode 100644 2-design-patterns/ch04-solid/06_misc/go.mod create mode 100644 2-design-patterns/ch05-decoration/01_reader_writer/go.mod delete mode 100644 2-design-patterns/ch05-decoration/01_reader_writer/init delete mode 100755 2-design-patterns/ch05-decoration/01_reader_writer/init-windows.sh rename 2-design-patterns/ch05-decoration/02_decorator/{src => }/decorator/decorator.go (100%) rename 2-design-patterns/ch05-decoration/02_decorator/{src => }/decorator/requestor.go (100%) rename 2-design-patterns/ch05-decoration/02_decorator/{src => }/decorator/simple_log.go (100%) rename 2-design-patterns/ch05-decoration/02_decorator/{src => }/easy_metrics/metrics.go (100%) create mode 100644 2-design-patterns/ch05-decoration/02_decorator/go.mod create mode 100644 2-design-patterns/ch05-decoration/02_decorator/go.sum delete mode 100644 2-design-patterns/ch05-decoration/02_decorator/init delete mode 100755 2-design-patterns/ch05-decoration/02_decorator/init-windows.sh create mode 100644 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/go.mod delete mode 100644 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init delete mode 100755 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init-windows.sh rename {5-appendix/01_no-imports/src => 2-design-patterns/ch06-onion-arch/01_dependency-rule-good}/packagea/featurea.go (58%) rename 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/{src => }/packageb/featureb.go (100%) create mode 100644 2-design-patterns/ch06-onion-arch/02_circulardep/go.mod delete mode 100644 2-design-patterns/ch06-onion-arch/02_circulardep/init delete mode 100755 2-design-patterns/ch06-onion-arch/02_circulardep/init-windows.sh rename 2-design-patterns/ch06-onion-arch/02_circulardep/{src => }/packagea/featurea.go (63%) rename 2-design-patterns/ch06-onion-arch/02_circulardep/{src => }/packageb/featureb.go (63%) create mode 100644 2-design-patterns/ch06-onion-arch/03_observer/go.mod delete mode 100644 2-design-patterns/ch06-onion-arch/03_observer/init delete mode 100755 2-design-patterns/ch06-onion-arch/03_observer/init-windows.sh rename 2-design-patterns/ch06-onion-arch/03_observer/{src => }/observer/observer.go (100%) rename 2-design-patterns/ch06-onion-arch/03_observer/{src => }/observer/subject.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/domain/api.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/domain/domain.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/domain/file.go (99%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/domain/log_file.go (100%) create mode 100644 2-design-patterns/ch06-onion-arch/04_onion/go.mod create mode 100644 2-design-patterns/ch06-onion-arch/04_onion/go.sum rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/infrastructure/gcphandler.go (96%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/infrastructure/infrastructure_test/localhandler_test.go (92%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/infrastructure/localhandler.go (84%) delete mode 100644 2-design-patterns/ch06-onion-arch/04_onion/init delete mode 100755 2-design-patterns/ch06-onion-arch/04_onion/init-windows.sh rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/gcpstorage.go (94%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/impl.go_STOP (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/interfaces_test/webservice_test.go (87%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/localstorage.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/webservice.go (96%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/interfaces/webservice_helpers.go (92%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/usecases/usecases.go (94%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/utils/logger.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/utils/options.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/utils/utils.go (100%) rename 2-design-patterns/ch06-onion-arch/04_onion/{src => }/utils/utils_test/utils_test.go (98%) create mode 100644 3-functional-techniques/ch07-func-param/01_func_param/go.mod create mode 100644 3-functional-techniques/ch07-func-param/01_func_param/go.sum delete mode 100644 3-functional-techniques/ch07-func-param/01_func_param/init delete mode 100755 3-functional-techniques/ch07-func-param/01_func_param/init-windows.sh rename 3-functional-techniques/ch07-func-param/01_func_param/{src => }/server/server.go (100%) rename 3-functional-techniques/ch07-func-param/01_func_param/{src => }/server/server_options.go (92%) rename 3-functional-techniques/ch07-func-param/01_func_param/{src => }/utils/logger.go (100%) rename 3-functional-techniques/ch07-func-param/01_func_param/{src => }/utils/options.go (100%) rename 3-functional-techniques/ch07-func-param/01_func_param/{src => }/utils/utils.go (100%) rename {4-purely-functional/ch10-monads/01_car_steps/src => 3-functional-techniques/ch07-func-param/01_func_param}/utils/utils_test/utils_test.go (97%) create mode 100644 3-functional-techniques/ch08-pipelining/01_imperative/go.mod delete mode 100644 3-functional-techniques/ch08-pipelining/01_imperative/init delete mode 100755 3-functional-techniques/ch08-pipelining/01_imperative/init-windows.sh create mode 100644 3-functional-techniques/ch08-pipelining/02_concurrent/go.mod delete mode 100644 3-functional-techniques/ch08-pipelining/02_concurrent/init delete mode 100755 3-functional-techniques/ch08-pipelining/02_concurrent/init-windows.sh create mode 100644 3-functional-techniques/ch08-pipelining/03_buffered/go.mod delete mode 100644 3-functional-techniques/ch08-pipelining/03_buffered/init delete mode 100755 3-functional-techniques/ch08-pipelining/03_buffered/init-windows.sh create mode 100644 3-functional-techniques/ch08-pipelining/04_buffered_cpus/go.mod delete mode 100644 3-functional-techniques/ch08-pipelining/04_buffered_cpus/init delete mode 100755 3-functional-techniques/ch08-pipelining/04_buffered_cpus/init-windows.sh create mode 100644 3-functional-techniques/ch08-pipelining/go.mod create mode 100644 3-functional-techniques/ch08-pipelining/go.sum rename 4-purely-functional/ch09-functor-monoid/01_clock_functor/{src => }/functor/clock.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/01_clock_functor/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/01_clock_functor/init delete mode 100755 4-purely-functional/ch09-functor-monoid/01_clock_functor/init-windows.sh create mode 100644 4-purely-functional/ch09-functor-monoid/01_no_generics_nums/go.mod rename 4-purely-functional/ch09-functor-monoid/02_generics_cars/{src => }/car/car_slice.go (100%) rename 4-purely-functional/ch09-functor-monoid/02_generics_cars/{src => }/car/types.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/02_generics_cars/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/02_generics_cars/init delete mode 100755 4-purely-functional/ch09-functor-monoid/02_generics_cars/init-windows.sh create mode 100644 4-purely-functional/ch09-functor-monoid/03_generics_nums/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/03_generics_nums/init delete mode 100755 4-purely-functional/ch09-functor-monoid/03_generics_nums/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/complex128_slice.go (100%) rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/float64_slice.go (100%) rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/int32_slice.go (100%) rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/int8_slice.go (100%) rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/types.go (100%) rename 4-purely-functional/ch09-functor-monoid/03_generics_nums/{src => }/num/vars.go (100%) rename 4-purely-functional/ch09-functor-monoid/05_int_functor/{src => }/functor/ints.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/05_int_functor/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/05_int_functor/init delete mode 100755 4-purely-functional/ch09-functor-monoid/05_int_functor/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/06_compose/{src => }/compose/compose.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/06_compose/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/06_compose/init delete mode 100755 4-purely-functional/ch09-functor-monoid/06_compose/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/07_compose_gof/{src => }/compose/compose.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/07_compose_gof/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/07_compose_gof/init delete mode 100755 4-purely-functional/ch09-functor-monoid/07_compose_gof/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/08_compose_fog/{src => }/compose/compose.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/08_compose_fog/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/08_compose_fog/init delete mode 100755 4-purely-functional/ch09-functor-monoid/08_compose_fog/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/09_clock_functor/{src => }/functor/clock.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/09_clock_functor/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/09_clock_functor/init delete mode 100755 4-purely-functional/ch09-functor-monoid/09_clock_functor/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/10_car_functor/{src => }/functor/car.go (100%) create mode 100644 4-purely-functional/ch09-functor-monoid/10_car_functor/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/10_car_functor/init delete mode 100755 4-purely-functional/ch09-functor-monoid/10_car_functor/init-windows.sh create mode 100644 4-purely-functional/ch09-functor-monoid/11_monoid/go.mod delete mode 100644 4-purely-functional/ch09-functor-monoid/11_monoid/init delete mode 100755 4-purely-functional/ch09-functor-monoid/11_monoid/init-windows.sh rename 4-purely-functional/ch09-functor-monoid/11_monoid/{src => }/monoid/README.md (100%) rename 4-purely-functional/ch09-functor-monoid/11_monoid/{src => }/monoid/int_monoid.go (100%) rename 4-purely-functional/ch09-functor-monoid/11_monoid/{src => }/monoid/lineitem_monoid.go (100%) rename 4-purely-functional/ch09-functor-monoid/11_monoid/{src => }/monoid/name_monoid.go (100%) create mode 100644 4-purely-functional/ch10-monads/01_car_steps/go.mod create mode 100644 4-purely-functional/ch10-monads/01_car_steps/go.sum delete mode 100644 4-purely-functional/ch10-monads/01_car_steps/init delete mode 100755 4-purely-functional/ch10-monads/01_car_steps/init-windows.sh rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/utils/logger.go (100%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/utils/options.go (100%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/utils/utils.go (100%) rename {3-functional-techniques/ch07-func-param/01_func_param/src => 4-purely-functional/ch10-monads/01_car_steps}/utils/utils_test/utils_test.go (97%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/workflow/car_types.go (100%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/workflow/monad.go (100%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/workflow/process_car_steps.go (93%) rename 4-purely-functional/ch10-monads/01_car_steps/{src => }/workflow/toolbox.go (100%) create mode 100644 4-purely-functional/ch10-monads/02_error_checker/go.mod delete mode 100644 4-purely-functional/ch10-monads/02_error_checker/init delete mode 100755 4-purely-functional/ch10-monads/02_error_checker/init-windows.sh create mode 100644 4-purely-functional/ch10-monads/03_y_combinator/go.mod delete mode 100644 4-purely-functional/ch10-monads/03_y_combinator/init delete mode 100755 4-purely-functional/ch10-monads/03_y_combinator/init-windows.sh create mode 100644 4-purely-functional/ch10-monads/04_i18n/go.mod create mode 100644 4-purely-functional/ch10-monads/04_i18n/go.sum rename 4-purely-functional/ch10-monads/04_i18n/{src => }/i18n/errors.go (100%) delete mode 100644 4-purely-functional/ch10-monads/04_i18n/init delete mode 100755 4-purely-functional/ch10-monads/04_i18n/init-windows.sh create mode 100644 4-purely-functional/ch10-monads/05_typeclasss/go.mod delete mode 100644 4-purely-functional/ch10-monads/05_typeclasss/init delete mode 100755 4-purely-functional/ch10-monads/05_typeclasss/init-windows.sh rename 4-purely-functional/ch10-monads/05_typeclasss/{src => }/typeclass/equals.go (100%) rename 4-purely-functional/ch10-monads/05_typeclasss/{src => }/typeclass/sum.go (100%) create mode 100644 4-purely-functional/ch11-category-theory/01_essense_of_iterator/go.mod delete mode 100644 4-purely-functional/ch11-category-theory/01_essense_of_iterator/init delete mode 100755 4-purely-functional/ch11-category-theory/01_essense_of_iterator/init-windows.sh create mode 100644 4-purely-functional/ch11-category-theory/02_anonymous/go.mod create mode 100644 4-purely-functional/ch11-category-theory/03_lambda/go.mod create mode 100644 4-purely-functional/ch11-category-theory/04_lambda/go.mod create mode 100644 4-purely-functional/ch11-category-theory/05_typeinferer/go.mod create mode 100644 5-appendix/01_no-imports/go.mod delete mode 100644 5-appendix/01_no-imports/init delete mode 100755 5-appendix/01_no-imports/init-windows.sh rename {2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src => 5-appendix/01_no-imports}/packagea/featurea.go (64%) rename 5-appendix/01_no-imports/{src => }/packageb/featureb.go (100%) create mode 100644 5-appendix/02_dependency-with-import/go.mod delete mode 100644 5-appendix/02_dependency-with-import/init delete mode 100755 5-appendix/02_dependency-with-import/init-windows.sh rename 5-appendix/02_dependency-with-import/{src => }/packagea/featurea.go (67%) rename 5-appendix/02_dependency-with-import/{src => }/packageb/featureb.go (100%) create mode 100644 5-appendix/03_with-third-party-import/go.mod create mode 100644 5-appendix/03_with-third-party-import/go.sum delete mode 100644 5-appendix/03_with-third-party-import/init delete mode 100755 5-appendix/03_with-third-party-import/init-windows.sh rename 5-appendix/03_with-third-party-import/{src => }/packagea/featurea.go (76%) rename 5-appendix/03_with-third-party-import/{src => }/packageb/featureb.go (100%) create mode 100755 go-init diff --git a/.dockerignore b/.dockerignore index 2bad11d..1a867b4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,4 @@ !fs/ !go-env !go-ide +!go-init diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/go.mod b/1-functional-fundamentals/ch01-pure-fp/01_oop/go.mod new file mode 100644 index 0000000..f8e7be9 --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/01_oop/go.mod @@ -0,0 +1,3 @@ +module 01_oop + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/init b/1-functional-fundamentals/ch01-pure-fp/01_oop/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/01_oop/init-windows.sh deleted file mode 100755 index 52280ec..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/init-windows.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -rm -rf $GOPATH\\golang.org\\x\\tools 2>/dev/null -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -rm -rf github.com/Masterminds/glide 2>/dev/null -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go b/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go index da5506b..d3ae73e 100644 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go +++ b/1-functional-fundamentals/ch01-pure-fp/01_oop/main.go @@ -1,8 +1,8 @@ package main import ( + "01_oop/oop" "fmt" - "oop" ) func main() { diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/src/oop/cars.go b/1-functional-fundamentals/ch01-pure-fp/01_oop/oop/cars.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/01_oop/src/oop/cars.go rename to 1-functional-fundamentals/ch01-pure-fp/01_oop/oop/cars.go diff --git a/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve b/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve deleted file mode 160000 index 333e84a..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/01_oop/src/github.com/go-delve/delve +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 333e84a0cb209a9ec762b753cbd4ecbc679104d4 diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/channel.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/channel.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/channel.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/channel.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/channel_test.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/channel_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/channel_test.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/channel_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/memoize.go_ORIG b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/memoize.go_ORIG similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/memoize.go_ORIG rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/memoize.go_ORIG diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/memoize_test.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/memoize_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/memoize_test.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/memoize_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/meomoize.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/meomoize.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/meomoize.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/meomoize.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/simple.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/simple.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/simple.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/simple.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/simple_test.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/simple_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/02_fib/src/fibonacci/simple_test.go rename to 1-functional-fundamentals/ch01-pure-fp/02_fib/fibonacci/simple_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/go.mod b/1-functional-fundamentals/ch01-pure-fp/02_fib/go.mod new file mode 100644 index 0000000..2940eff --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/02_fib/go.mod @@ -0,0 +1,3 @@ +module 02_fib + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/init b/1-functional-fundamentals/ch01-pure-fp/02_fib/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/02_fib/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/02_fib/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/02_fib/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch01-pure-fp/02_fib/main.go b/1-functional-fundamentals/ch01-pure-fp/02_fib/main.go index 69811ef..126c8f7 100644 --- a/1-functional-fundamentals/ch01-pure-fp/02_fib/main.go +++ b/1-functional-fundamentals/ch01-pure-fp/02_fib/main.go @@ -1,7 +1,7 @@ package main import ( - "fibonacci" + "02_fib/fibonacci" ) func main() { diff --git a/1-functional-fundamentals/ch01-pure-fp/03_anonymous/go.mod b/1-functional-fundamentals/ch01-pure-fp/03_anonymous/go.mod new file mode 100644 index 0000000..9d9fc1c --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/03_anonymous/go.mod @@ -0,0 +1,3 @@ +module 03_anonymous + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init b/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/03_anonymous/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch01-pure-fp/04_greeting/go.mod b/1-functional-fundamentals/ch01-pure-fp/04_greeting/go.mod new file mode 100644 index 0000000..1de5f9d --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/04_greeting/go.mod @@ -0,0 +1,3 @@ +module 04_greeting + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/04_greeting/init b/1-functional-fundamentals/ch01-pure-fp/04_greeting/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/04_greeting/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/04_greeting/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/04_greeting/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/04_greeting/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/go.mod b/1-functional-fundamentals/ch01-pure-fp/05_sum/go.mod new file mode 100644 index 0000000..be4288a --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/05_sum/go.mod @@ -0,0 +1,3 @@ +module 05_sum + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/init b/1-functional-fundamentals/ch01-pure-fp/05_sum/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/05_sum/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/05_sum/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/05_sum/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/loop.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/loop.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/loop.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/loop.go diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/loop_test.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/loop_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/loop_test.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/loop_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/recursive.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/recursive.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/recursive.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/recursive.go diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/recursive_test.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/recursive_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/recursive_test.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/recursive_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/tailcall.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/tailcall.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/tailcall.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/tailcall.go diff --git a/1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/tailcall_test.go b/1-functional-fundamentals/ch01-pure-fp/05_sum/sum/tailcall_test.go similarity index 100% rename from 1-functional-fundamentals/ch01-pure-fp/05_sum/src/sum/tailcall_test.go rename to 1-functional-fundamentals/ch01-pure-fp/05_sum/sum/tailcall_test.go diff --git a/1-functional-fundamentals/ch01-pure-fp/06_curry/go.mod b/1-functional-fundamentals/ch01-pure-fp/06_curry/go.mod new file mode 100644 index 0000000..0654de0 --- /dev/null +++ b/1-functional-fundamentals/ch01-pure-fp/06_curry/go.mod @@ -0,0 +1,3 @@ +module 06_curry + +go 1.18 diff --git a/1-functional-fundamentals/ch01-pure-fp/06_curry/init b/1-functional-fundamentals/ch01-pure-fp/06_curry/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/06_curry/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch01-pure-fp/06_curry/init-windows.sh b/1-functional-fundamentals/ch01-pure-fp/06_curry/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch01-pure-fp/06_curry/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch02-collections/01_iterator/go.mod b/1-functional-fundamentals/ch02-collections/01_iterator/go.mod new file mode 100644 index 0000000..deea7fe --- /dev/null +++ b/1-functional-fundamentals/ch02-collections/01_iterator/go.mod @@ -0,0 +1,3 @@ +module 01_iterator + +go 1.18 diff --git a/1-functional-fundamentals/ch02-collections/01_iterator/init b/1-functional-fundamentals/ch02-collections/01_iterator/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch02-collections/01_iterator/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch02-collections/01_iterator/init-windows.sh b/1-functional-fundamentals/ch02-collections/01_iterator/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch02-collections/01_iterator/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch02-collections/02_chainlink/go.mod b/1-functional-fundamentals/ch02-collections/02_chainlink/go.mod new file mode 100644 index 0000000..850cafd --- /dev/null +++ b/1-functional-fundamentals/ch02-collections/02_chainlink/go.mod @@ -0,0 +1,3 @@ +module 02_chainlink + +go 1.18 diff --git a/1-functional-fundamentals/ch02-collections/02_chainlink/init b/1-functional-fundamentals/ch02-collections/02_chainlink/init deleted file mode 100755 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch02-collections/02_chainlink/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch02-collections/02_chainlink/init-windows.sh b/1-functional-fundamentals/ch02-collections/02_chainlink/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch02-collections/02_chainlink/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch03-hof/01_cps/go.mod b/1-functional-fundamentals/ch03-hof/01_cps/go.mod new file mode 100644 index 0000000..a87df68 --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/01_cps/go.mod @@ -0,0 +1,3 @@ +module 01_cps + +go 1.18 diff --git a/1-functional-fundamentals/ch03-hof/01_cps/init b/1-functional-fundamentals/ch03-hof/01_cps/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch03-hof/01_cps/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch03-hof/01_cps/init-windows.sh b/1-functional-fundamentals/ch03-hof/01_cps/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch03-hof/01_cps/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch03-hof/02_fcn_comp/go.mod b/1-functional-fundamentals/ch03-hof/02_fcn_comp/go.mod new file mode 100644 index 0000000..e2bd10c --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/02_fcn_comp/go.mod @@ -0,0 +1,3 @@ +module 02_fcn_comp + +go 1.18 diff --git a/1-functional-fundamentals/ch03-hof/02_fcn_comp/init b/1-functional-fundamentals/ch03-hof/02_fcn_comp/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch03-hof/02_fcn_comp/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch03-hof/02_fcn_comp/init-windows.sh b/1-functional-fundamentals/ch03-hof/02_fcn_comp/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch03-hof/02_fcn_comp/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch03-hof/03_hof/go.mod b/1-functional-fundamentals/ch03-hof/03_hof/go.mod new file mode 100644 index 0000000..1480d16 --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/03_hof/go.mod @@ -0,0 +1,5 @@ +module 03_hof + +go 1.18 + +require github.com/julienschmidt/httprouter v1.3.0 diff --git a/1-functional-fundamentals/ch03-hof/03_hof/go.sum b/1-functional-fundamentals/ch03-hof/03_hof/go.sum new file mode 100644 index 0000000..096c54e --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/03_hof/go.sum @@ -0,0 +1,2 @@ +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/1-functional-fundamentals/ch03-hof/03_hof/src/hof/cars.go b/1-functional-fundamentals/ch03-hof/03_hof/hof/cars.go similarity index 100% rename from 1-functional-fundamentals/ch03-hof/03_hof/src/hof/cars.go rename to 1-functional-fundamentals/ch03-hof/03_hof/hof/cars.go diff --git a/1-functional-fundamentals/ch03-hof/03_hof/src/hof/generator.go b/1-functional-fundamentals/ch03-hof/03_hof/hof/generator.go similarity index 100% rename from 1-functional-fundamentals/ch03-hof/03_hof/src/hof/generator.go rename to 1-functional-fundamentals/ch03-hof/03_hof/hof/generator.go diff --git a/1-functional-fundamentals/ch03-hof/03_hof/src/hof/restful.go b/1-functional-fundamentals/ch03-hof/03_hof/hof/restful.go similarity index 100% rename from 1-functional-fundamentals/ch03-hof/03_hof/src/hof/restful.go rename to 1-functional-fundamentals/ch03-hof/03_hof/hof/restful.go diff --git a/1-functional-fundamentals/ch03-hof/03_hof/src/hof/types.go b/1-functional-fundamentals/ch03-hof/03_hof/hof/types.go similarity index 100% rename from 1-functional-fundamentals/ch03-hof/03_hof/src/hof/types.go rename to 1-functional-fundamentals/ch03-hof/03_hof/hof/types.go diff --git a/1-functional-fundamentals/ch03-hof/03_hof/src/hof/utils.go b/1-functional-fundamentals/ch03-hof/03_hof/hof/utils.go similarity index 100% rename from 1-functional-fundamentals/ch03-hof/03_hof/src/hof/utils.go rename to 1-functional-fundamentals/ch03-hof/03_hof/hof/utils.go diff --git a/1-functional-fundamentals/ch03-hof/03_hof/init b/1-functional-fundamentals/ch03-hof/03_hof/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch03-hof/03_hof/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch03-hof/03_hof/init-windows.sh b/1-functional-fundamentals/ch03-hof/03_hof/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch03-hof/03_hof/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch03-hof/03_hof/main.go b/1-functional-fundamentals/ch03-hof/03_hof/main.go index 01f6cba..a2aeaad 100644 --- a/1-functional-fundamentals/ch03-hof/03_hof/main.go +++ b/1-functional-fundamentals/ch03-hof/03_hof/main.go @@ -1,7 +1,7 @@ package main import ( - . "hof" + . "03_hof/hof" "log" "os" "github.com/julienschmidt/httprouter" diff --git a/1-functional-fundamentals/ch03-hof/04_scoping/go.mod b/1-functional-fundamentals/ch03-hof/04_scoping/go.mod new file mode 100644 index 0000000..5a8bd08 --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/04_scoping/go.mod @@ -0,0 +1,3 @@ +module 04_scoping + +go 1.18 diff --git a/1-functional-fundamentals/ch03-hof/04_scoping/init b/1-functional-fundamentals/ch03-hof/04_scoping/init deleted file mode 100644 index 2f6a36c..0000000 --- a/1-functional-fundamentals/ch03-hof/04_scoping/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/1-functional-fundamentals/ch03-hof/04_scoping/init-windows.sh b/1-functional-fundamentals/ch03-hof/04_scoping/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/1-functional-fundamentals/ch03-hof/04_scoping/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/1-functional-fundamentals/ch03-hof/05_closure/go.mod b/1-functional-fundamentals/ch03-hof/05_closure/go.mod new file mode 100644 index 0000000..bd5ae60 --- /dev/null +++ b/1-functional-fundamentals/ch03-hof/05_closure/go.mod @@ -0,0 +1,3 @@ +module 05_closure + +go 1.18 diff --git a/2-design-patterns/ch04-solid/01_lambda/go.mod b/2-design-patterns/ch04-solid/01_lambda/go.mod new file mode 100644 index 0000000..1cc4bfc --- /dev/null +++ b/2-design-patterns/ch04-solid/01_lambda/go.mod @@ -0,0 +1,3 @@ +module 01_lambda + +go 1.18 diff --git a/2-design-patterns/ch04-solid/01_lambda/init b/2-design-patterns/ch04-solid/01_lambda/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch04-solid/01_lambda/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch04-solid/01_lambda/init-windows.sh b/2-design-patterns/ch04-solid/01_lambda/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch04-solid/01_lambda/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch04-solid/02_maybe/go.mod b/2-design-patterns/ch04-solid/02_maybe/go.mod new file mode 100644 index 0000000..5ae4893 --- /dev/null +++ b/2-design-patterns/ch04-solid/02_maybe/go.mod @@ -0,0 +1,3 @@ +module 02_maybe + +go 1.18 diff --git a/2-design-patterns/ch04-solid/02_maybe/init b/2-design-patterns/ch04-solid/02_maybe/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch04-solid/02_maybe/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch04-solid/02_maybe/init-windows.sh b/2-design-patterns/ch04-solid/02_maybe/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch04-solid/02_maybe/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch04-solid/02_maybe/main.go b/2-design-patterns/ch04-solid/02_maybe/main.go index fcf1f16..60748b4 100644 --- a/2-design-patterns/ch04-solid/02_maybe/main.go +++ b/2-design-patterns/ch04-solid/02_maybe/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "maybe" + "02_maybe/maybe" ) type Work struct { Succeeded bool } diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/either.go b/2-design-patterns/ch04-solid/02_maybe/maybe/either.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/either.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/either.go diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/either_error.go b/2-design-patterns/ch04-solid/02_maybe/maybe/either_error.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/either_error.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/either_error.go diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/option.go b/2-design-patterns/ch04-solid/02_maybe/maybe/option.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/option.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/option.go diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/option_error.go b/2-design-patterns/ch04-solid/02_maybe/maybe/option_error.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/option_error.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/option_error.go diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/string_either.go b/2-design-patterns/ch04-solid/02_maybe/maybe/string_either.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/string_either.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/string_either.go diff --git a/2-design-patterns/ch04-solid/02_maybe/src/maybe/string_option.go b/2-design-patterns/ch04-solid/02_maybe/maybe/string_option.go similarity index 100% rename from 2-design-patterns/ch04-solid/02_maybe/src/maybe/string_option.go rename to 2-design-patterns/ch04-solid/02_maybe/maybe/string_option.go diff --git a/2-design-patterns/ch04-solid/03_car/src/car/car.go b/2-design-patterns/ch04-solid/03_car/car/car.go similarity index 100% rename from 2-design-patterns/ch04-solid/03_car/src/car/car.go rename to 2-design-patterns/ch04-solid/03_car/car/car.go diff --git a/2-design-patterns/ch04-solid/03_car/go.mod b/2-design-patterns/ch04-solid/03_car/go.mod new file mode 100644 index 0000000..d985654 --- /dev/null +++ b/2-design-patterns/ch04-solid/03_car/go.mod @@ -0,0 +1,3 @@ +module 03_car + +go 1.18 diff --git a/2-design-patterns/ch04-solid/03_car/init b/2-design-patterns/ch04-solid/03_car/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch04-solid/03_car/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch04-solid/03_car/init-windows.sh b/2-design-patterns/ch04-solid/03_car/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch04-solid/03_car/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch04-solid/03_car/main.go b/2-design-patterns/ch04-solid/03_car/main.go index ef8f682..ddac321 100644 --- a/2-design-patterns/ch04-solid/03_car/main.go +++ b/2-design-patterns/ch04-solid/03_car/main.go @@ -1,7 +1,7 @@ package main import ( - . "car" + . "03_car/car" "fmt" ) diff --git a/2-design-patterns/ch04-solid/05_duck/go.mod b/2-design-patterns/ch04-solid/05_duck/go.mod new file mode 100644 index 0000000..4b1fdda --- /dev/null +++ b/2-design-patterns/ch04-solid/05_duck/go.mod @@ -0,0 +1,3 @@ +module 05_duck + +go 1.18 diff --git a/2-design-patterns/ch04-solid/05_duck/init b/2-design-patterns/ch04-solid/05_duck/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch04-solid/05_duck/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch04-solid/05_duck/init-windows.sh b/2-design-patterns/ch04-solid/05_duck/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch04-solid/05_duck/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch04-solid/06_misc/go.mod b/2-design-patterns/ch04-solid/06_misc/go.mod new file mode 100644 index 0000000..b07bd4f --- /dev/null +++ b/2-design-patterns/ch04-solid/06_misc/go.mod @@ -0,0 +1,3 @@ +module 06_misc + +go 1.18 diff --git a/2-design-patterns/ch05-decoration/01_reader_writer/go.mod b/2-design-patterns/ch05-decoration/01_reader_writer/go.mod new file mode 100644 index 0000000..ce5f7c7 --- /dev/null +++ b/2-design-patterns/ch05-decoration/01_reader_writer/go.mod @@ -0,0 +1,3 @@ +module 01_reader_writer + +go 1.18 diff --git a/2-design-patterns/ch05-decoration/01_reader_writer/init b/2-design-patterns/ch05-decoration/01_reader_writer/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch05-decoration/01_reader_writer/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch05-decoration/01_reader_writer/init-windows.sh b/2-design-patterns/ch05-decoration/01_reader_writer/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch05-decoration/01_reader_writer/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch05-decoration/02_decorator/src/decorator/decorator.go b/2-design-patterns/ch05-decoration/02_decorator/decorator/decorator.go similarity index 100% rename from 2-design-patterns/ch05-decoration/02_decorator/src/decorator/decorator.go rename to 2-design-patterns/ch05-decoration/02_decorator/decorator/decorator.go diff --git a/2-design-patterns/ch05-decoration/02_decorator/src/decorator/requestor.go b/2-design-patterns/ch05-decoration/02_decorator/decorator/requestor.go similarity index 100% rename from 2-design-patterns/ch05-decoration/02_decorator/src/decorator/requestor.go rename to 2-design-patterns/ch05-decoration/02_decorator/decorator/requestor.go diff --git a/2-design-patterns/ch05-decoration/02_decorator/src/decorator/simple_log.go b/2-design-patterns/ch05-decoration/02_decorator/decorator/simple_log.go similarity index 100% rename from 2-design-patterns/ch05-decoration/02_decorator/src/decorator/simple_log.go rename to 2-design-patterns/ch05-decoration/02_decorator/decorator/simple_log.go diff --git a/2-design-patterns/ch05-decoration/02_decorator/src/easy_metrics/metrics.go b/2-design-patterns/ch05-decoration/02_decorator/easy_metrics/metrics.go similarity index 100% rename from 2-design-patterns/ch05-decoration/02_decorator/src/easy_metrics/metrics.go rename to 2-design-patterns/ch05-decoration/02_decorator/easy_metrics/metrics.go diff --git a/2-design-patterns/ch05-decoration/02_decorator/go.mod b/2-design-patterns/ch05-decoration/02_decorator/go.mod new file mode 100644 index 0000000..121f2b1 --- /dev/null +++ b/2-design-patterns/ch05-decoration/02_decorator/go.mod @@ -0,0 +1,5 @@ +module 02_decorator + +go 1.18 + +require github.com/admobi/easy-metrics v0.0.0-20170704124055-5ed4e60cf060 diff --git a/2-design-patterns/ch05-decoration/02_decorator/go.sum b/2-design-patterns/ch05-decoration/02_decorator/go.sum new file mode 100644 index 0000000..7376ecb --- /dev/null +++ b/2-design-patterns/ch05-decoration/02_decorator/go.sum @@ -0,0 +1,2 @@ +github.com/admobi/easy-metrics v0.0.0-20170704124055-5ed4e60cf060 h1:kAKDYIJngW6gE7+4CVxJJdNdEGCFXYV5pyR2V7zcJsE= +github.com/admobi/easy-metrics v0.0.0-20170704124055-5ed4e60cf060/go.mod h1:RyhHk4TrpB36sebDfJRQQg6QQ4A8JphX0239V5QB0zU= diff --git a/2-design-patterns/ch05-decoration/02_decorator/init b/2-design-patterns/ch05-decoration/02_decorator/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch05-decoration/02_decorator/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch05-decoration/02_decorator/init-windows.sh b/2-design-patterns/ch05-decoration/02_decorator/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch05-decoration/02_decorator/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch05-decoration/02_decorator/main.go b/2-design-patterns/ch05-decoration/02_decorator/main.go index 25ac93c..b2a4d17 100644 --- a/2-design-patterns/ch05-decoration/02_decorator/main.go +++ b/2-design-patterns/ch05-decoration/02_decorator/main.go @@ -11,8 +11,8 @@ import ( "os" "os/signal" "time" - "easy_metrics" - dec "decorator" + "02_decorator/easy_metrics" + dec "02_decorator/decorator" ) const ( diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/go.mod b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/go.mod new file mode 100644 index 0000000..42c0b28 --- /dev/null +++ b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/go.mod @@ -0,0 +1,3 @@ +module 01_dependency-rule-good + +go 1.18 diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init-windows.sh b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/main.go b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/main.go index fc4e995..37bb4f6 100644 --- a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/main.go +++ b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/main.go @@ -1,7 +1,7 @@ package main import ( - a "packagea" + a "01_dependency-rule-good/packagea" ) func main() { diff --git a/5-appendix/01_no-imports/src/packagea/featurea.go b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/packagea/featurea.go similarity index 58% rename from 5-appendix/01_no-imports/src/packagea/featurea.go rename to 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/packagea/featurea.go index 40e0165..194a5ed 100644 --- a/5-appendix/01_no-imports/src/packagea/featurea.go +++ b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/packagea/featurea.go @@ -1,6 +1,6 @@ package packagea -import b "packageb" +import b "01_dependency-rule-good/packageb" func Atask() { println("A") diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src/packageb/featureb.go b/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/packageb/featureb.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src/packageb/featureb.go rename to 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/packageb/featureb.go diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/go.mod b/2-design-patterns/ch06-onion-arch/02_circulardep/go.mod new file mode 100644 index 0000000..3ee99eb --- /dev/null +++ b/2-design-patterns/ch06-onion-arch/02_circulardep/go.mod @@ -0,0 +1,3 @@ +module 02_circulardep + +go 1.18 diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/init b/2-design-patterns/ch06-onion-arch/02_circulardep/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch06-onion-arch/02_circulardep/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/init-windows.sh b/2-design-patterns/ch06-onion-arch/02_circulardep/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch06-onion-arch/02_circulardep/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/main.go b/2-design-patterns/ch06-onion-arch/02_circulardep/main.go index 15af0b2..8581265 100644 --- a/2-design-patterns/ch06-onion-arch/02_circulardep/main.go +++ b/2-design-patterns/ch06-onion-arch/02_circulardep/main.go @@ -1,6 +1,6 @@ package main -import a "packagea" +import a "02_circulardep/packagea" func main() { a.Atask() diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/src/packagea/featurea.go b/2-design-patterns/ch06-onion-arch/02_circulardep/packagea/featurea.go similarity index 63% rename from 2-design-patterns/ch06-onion-arch/02_circulardep/src/packagea/featurea.go rename to 2-design-patterns/ch06-onion-arch/02_circulardep/packagea/featurea.go index 40e0165..0b3d0e4 100644 --- a/2-design-patterns/ch06-onion-arch/02_circulardep/src/packagea/featurea.go +++ b/2-design-patterns/ch06-onion-arch/02_circulardep/packagea/featurea.go @@ -1,6 +1,6 @@ package packagea -import b "packageb" +import b "02_circulardep/packageb" func Atask() { println("A") diff --git a/2-design-patterns/ch06-onion-arch/02_circulardep/src/packageb/featureb.go b/2-design-patterns/ch06-onion-arch/02_circulardep/packageb/featureb.go similarity index 63% rename from 2-design-patterns/ch06-onion-arch/02_circulardep/src/packageb/featureb.go rename to 2-design-patterns/ch06-onion-arch/02_circulardep/packageb/featureb.go index 4d5954b..3b12a64 100644 --- a/2-design-patterns/ch06-onion-arch/02_circulardep/src/packageb/featureb.go +++ b/2-design-patterns/ch06-onion-arch/02_circulardep/packageb/featureb.go @@ -1,6 +1,6 @@ package packageb -import a "packagea" +import a "02_circulardep/packagea" func Btask() { println("B") diff --git a/2-design-patterns/ch06-onion-arch/03_observer/go.mod b/2-design-patterns/ch06-onion-arch/03_observer/go.mod new file mode 100644 index 0000000..7d29831 --- /dev/null +++ b/2-design-patterns/ch06-onion-arch/03_observer/go.mod @@ -0,0 +1,3 @@ +module 03_observer + +go 1.18 diff --git a/2-design-patterns/ch06-onion-arch/03_observer/init b/2-design-patterns/ch06-onion-arch/03_observer/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch06-onion-arch/03_observer/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch06-onion-arch/03_observer/init-windows.sh b/2-design-patterns/ch06-onion-arch/03_observer/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch06-onion-arch/03_observer/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch06-onion-arch/03_observer/main.go b/2-design-patterns/ch06-onion-arch/03_observer/main.go index 7e03c22..eae77c8 100644 --- a/2-design-patterns/ch06-onion-arch/03_observer/main.go +++ b/2-design-patterns/ch06-onion-arch/03_observer/main.go @@ -1,7 +1,7 @@ package main import ( - . "observer" + . "03_observer/observer" ) func main() { diff --git a/2-design-patterns/ch06-onion-arch/03_observer/src/observer/observer.go b/2-design-patterns/ch06-onion-arch/03_observer/observer/observer.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/03_observer/src/observer/observer.go rename to 2-design-patterns/ch06-onion-arch/03_observer/observer/observer.go diff --git a/2-design-patterns/ch06-onion-arch/03_observer/src/observer/subject.go b/2-design-patterns/ch06-onion-arch/03_observer/observer/subject.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/03_observer/src/observer/subject.go rename to 2-design-patterns/ch06-onion-arch/03_observer/observer/subject.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/domain/api.go b/2-design-patterns/ch06-onion-arch/04_onion/domain/api.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/domain/api.go rename to 2-design-patterns/ch06-onion-arch/04_onion/domain/api.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/domain/domain.go b/2-design-patterns/ch06-onion-arch/04_onion/domain/domain.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/domain/domain.go rename to 2-design-patterns/ch06-onion-arch/04_onion/domain/domain.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/domain/file.go b/2-design-patterns/ch06-onion-arch/04_onion/domain/file.go similarity index 99% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/domain/file.go rename to 2-design-patterns/ch06-onion-arch/04_onion/domain/file.go index b2e63bb..1ceb32a 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/domain/file.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/domain/file.go @@ -6,7 +6,7 @@ import ( "encoding/json" "io/ioutil" "os/exec" - . "utils" + . "04_onion/utils" "bytes" "strings" "path/filepath" diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/domain/log_file.go b/2-design-patterns/ch06-onion-arch/04_onion/domain/log_file.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/domain/log_file.go rename to 2-design-patterns/ch06-onion-arch/04_onion/domain/log_file.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/go.mod b/2-design-patterns/ch06-onion-arch/04_onion/go.mod new file mode 100644 index 0000000..9ec338e --- /dev/null +++ b/2-design-patterns/ch06-onion-arch/04_onion/go.mod @@ -0,0 +1,32 @@ +module 04_onion + +go 1.18 + +require ( + cloud.google.com/go/storage v1.22.0 + github.com/BurntSushi/toml v1.1.0 + github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.8.1 + google.golang.org/api v0.80.0 +) + +require ( + cloud.google.com/go v0.100.2 // indirect + cloud.google.com/go/compute v1.6.1 // indirect + cloud.google.com/go/iam v0.3.0 // indirect + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.8 // indirect + github.com/googleapis/gax-go/v2 v2.3.0 // indirect + github.com/googleapis/go-type-adapters v1.0.0 // indirect + go.opencensus.io v0.23.0 // indirect + golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect + golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect + golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect + golang.org/x/text v0.3.7 // indirect + golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 // indirect + google.golang.org/grpc v1.46.0 // indirect + google.golang.org/protobuf v1.28.0 // indirect +) diff --git a/2-design-patterns/ch06-onion-arch/04_onion/go.sum b/2-design-patterns/ch06-onion-arch/04_onion/go.sum new file mode 100644 index 0000000..8fab101 --- /dev/null +++ b/2-design-patterns/ch06-onion-arch/04_onion/go.sum @@ -0,0 +1,645 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= +cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= +cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= +cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= +cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= +cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= +cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= +cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW4= +cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc= +cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA= +cloud.google.com/go v0.100.2 h1:t9Iw5QH5v4XtlEQaCtUY7x6sCABps8sW0acw7e2WQ6Y= +cloud.google.com/go v0.100.2/go.mod h1:4Xra9TjzAeYHrl5+oeLlzbM2k3mjVhZh4UqTZ//w99A= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/compute v0.1.0/go.mod h1:GAesmwr110a34z04OlxYkATPBEfVhkymfTBXtfbBFow= +cloud.google.com/go/compute v1.3.0/go.mod h1:cCZiE1NHEtai4wiufUhW8I8S1JKkAnhnQJWM7YD99wM= +cloud.google.com/go/compute v1.5.0/go.mod h1:9SMHyhJlzhlkJqrPAc839t2BZFTSk6Jdj6mkzQJeu0M= +cloud.google.com/go/compute v1.6.0/go.mod h1:T29tfhtVbq1wvAPo0E3+7vhgmkOYeXjhFvz/FMzPu0s= +cloud.google.com/go/compute v1.6.1 h1:2sMmt8prCn7DPaG4Pmh0N3Inmc8cT8ae5k1M6VJ9Wqc= +cloud.google.com/go/compute v1.6.1/go.mod h1:g85FgpzFvNULZ+S8AYq87axRKuf2Kh7deLqV/jJ3thU= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/iam v0.3.0 h1:exkAomrVUuzx9kWFI1wm3KI0uoDeUFPB4kKGzx6x+Gc= +cloud.google.com/go/iam v0.3.0/go.mod h1:XzJPvDayI+9zsASAFO68Hk07u3z+f+JrT2xXNdp4bnY= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +cloud.google.com/go/storage v1.22.0 h1:NUV0NNp9nkBuW66BFRLuMgldN60C57ET3dhbwLIYio8= +cloud.google.com/go/storage v1.22.0/go.mod h1:GbaLEoMqbVm6sx3Z0R++gSiBlgMv6yUi2q1DeGFKQgE= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.2.1 h1:d8MncMlErDFTwQGBK1xhv026j9kqhvw1Qv9IbWT1VLQ= +github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= +github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM= +github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/OthfcblKl4IGNaM= +github.com/googleapis/gax-go/v2 v2.3.0 h1:nRJtk3y8Fm770D42QV6T90ZnvFZyk7agSo3Q+Z9p3WI= +github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM= +github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA= +github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 h1:OSnWWcOd/CtWQC2cYSBgbTSJv3ciqd8r54ySIW2y3RE= +golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= +golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= +google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= +google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= +google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= +google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= +google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= +google.golang.org/api v0.55.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= +google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= +google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdrMgI= +google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= +google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo= +google.golang.org/api v0.67.0/go.mod h1:ShHKP8E60yPsKNw/w8w+VYaj9H6buA5UqDp8dhbQZ6g= +google.golang.org/api v0.70.0/go.mod h1:Bs4ZM2HGifEvXwd50TtW70ovgJffJYw2oRCOFU/SkfA= +google.golang.org/api v0.71.0/go.mod h1:4PyU6e6JogV1f9eA4voyrTY2batOLdgZ5qZ5HOCc4j8= +google.golang.org/api v0.74.0/go.mod h1:ZpfMZOVRMywNyvJFeqL9HRWBgAuRfSjJFpe9QtRRyDs= +google.golang.org/api v0.75.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69ljA= +google.golang.org/api v0.80.0 h1:IQWaGVCYnsm4MO3hh+WtSXMzMzuyFx/fuR8qkN3A0Qo= +google.golang.org/api v0.80.0/go.mod h1:xY3nI94gbvBrE0J6NHXhxOmW97HG7Khjkku6AFB3Hyg= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210329143202-679c6ae281ee/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= +google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20211221195035-429b39de9b1c/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220207164111-0872dc986b00/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= +google.golang.org/genproto v0.0.0-20220405205423-9d709892a2bf/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= +google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= +google.golang.org/genproto v0.0.0-20220413183235-5e96e2839df9/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= +google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= +google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= +google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 h1:q1kiSVscqoDeqTF27eQ2NnLLDmqF0I373qQNXYMy0fo= +google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= +google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= +google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/gcphandler.go b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/gcphandler.go similarity index 96% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/gcphandler.go rename to 2-design-patterns/ch06-onion-arch/04_onion/infrastructure/gcphandler.go index 3a60361..67b070d 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/gcphandler.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/gcphandler.go @@ -1,18 +1,19 @@ package infrastructure import ( - "cloud.google.com/go/storage" + "04_onion/domain" + "04_onion/interfaces" + "04_onion/usecases" + . "04_onion/utils" "context" - "google.golang.org/api/option" - "domain" - "google.golang.org/api/iterator" - . "utils" + "io" "io/ioutil" "os" - "io" - "interfaces" - "usecases" + + "cloud.google.com/go/storage" "github.com/pkg/errors" + "google.golang.org/api/iterator" + "google.golang.org/api/option" ) type GcpHandler struct { @@ -87,7 +88,6 @@ func (handler *GcpHandler) DownloadFile(fileName string) (success bool, err erro Debug.Printf("Config.SourceBucketName: %s", Config.SourceBucketName) Debug.Printf("fullFilePath: %s", fullFilePath) - bucketObject := handler.GetBucketObject(domain.SourceFlow, Config.GcpSourceProjectId, Config.SourceBucketName, fullFilePath) fr, err := bucketObject.NewReader(ctx) if err != nil { @@ -107,7 +107,7 @@ func (handler *GcpHandler) DownloadFile(fileName string) (success bool, err erro var cachedLogFiles []string for i, logFile := range *logFiles { logFileName = newFile.FullParsedFileName(i) - Info.Println("Encoding, caching and saving logFileName: "+logFileName) + Info.Println("Encoding, caching and saving logFileName: " + logFileName) logFileJson, err := logFile.ToJson() if err != nil { Error.Printf("Unable to encode logFileName (%s) - ERROR: %v", logFileName, err) @@ -150,7 +150,7 @@ func GetGcpInteractor() (gcpInteractor *usecases.GcpInteractor, err error) { if err != nil { return nil, errors.Wrap(err, "unable to create new sink gcp handler") } - handlers := make(map[string] interfaces.GcpHandler) + handlers := make(map[string]interfaces.GcpHandler) handlers["SourceBucketRepo"] = sourceHandler handlers["SinkBucketRepo"] = sinkHandler gcpInteractor = new(usecases.GcpInteractor) @@ -161,8 +161,6 @@ func GetGcpInteractor() (gcpInteractor *usecases.GcpInteractor, err error) { return GcpInteractor, err } - - type List interface { Cons(val interface{}) List ForEach(f func(interface{})) diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/infrastructure_test/localhandler_test.go b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/infrastructure_test/localhandler_test.go similarity index 92% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/infrastructure_test/localhandler_test.go rename to 2-design-patterns/ch06-onion-arch/04_onion/infrastructure/infrastructure_test/localhandler_test.go index 412d049..ebaf4e6 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/infrastructure_test/localhandler_test.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/infrastructure_test/localhandler_test.go @@ -1,8 +1,8 @@ package infrastructure_test import ( + "04_onion/infrastructure" "testing" - "infrastructure" ) func TestLocalInteractor(t *testing.T) { diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/localhandler.go b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/localhandler.go similarity index 84% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/localhandler.go rename to 2-design-patterns/ch06-onion-arch/04_onion/infrastructure/localhandler.go index 22421a2..97bb102 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/infrastructure/localhandler.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/infrastructure/localhandler.go @@ -1,14 +1,14 @@ package infrastructure import ( - "interfaces" - "usecases" - . "utils" + "04_onion/interfaces" + "04_onion/usecases" + . "04_onion/utils" "fmt" "os" ) -type LocalHandler struct {} +type LocalHandler struct{} var LocalInteractor *usecases.LocalInteractor @@ -28,11 +28,11 @@ func (handler *LocalHandler) FileExists(fileName string) (fileExists bool, err e func GetLocalInteractor() (localInteractor *usecases.LocalInteractor, err error) { if LocalInteractor == nil { localHandler := NewLocalHandler() - localHandlers := make(map[string] interfaces.LocalHandler) + localHandlers := make(map[string]interfaces.LocalHandler) localHandlers["LocalFileSystemRepo"] = localHandler localInteractor = new(usecases.LocalInteractor) localInteractor.LocalRepository = interfaces.NewLocalRepo(localHandlers) LocalInteractor = localInteractor } return LocalInteractor, nil -} \ No newline at end of file +} diff --git a/2-design-patterns/ch06-onion-arch/04_onion/init b/2-design-patterns/ch06-onion-arch/04_onion/init deleted file mode 100644 index 2f6a36c..0000000 --- a/2-design-patterns/ch06-onion-arch/04_onion/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/2-design-patterns/ch06-onion-arch/04_onion/init-windows.sh b/2-design-patterns/ch06-onion-arch/04_onion/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/2-design-patterns/ch06-onion-arch/04_onion/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/gcpstorage.go b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/gcpstorage.go similarity index 94% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/gcpstorage.go rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/gcpstorage.go index d5f0962..998e85b 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/gcpstorage.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/gcpstorage.go @@ -1,7 +1,7 @@ package interfaces import ( - "domain" + "04_onion/domain" ) type GcpHandler interface { @@ -22,8 +22,8 @@ type SinkBucketRepo GcpRepo func NewSourceBucketRepo(gcpHandlers map[string]GcpHandler) *SourceBucketRepo { return &SourceBucketRepo{ gcpHandlers: gcpHandlers, - gcpHandler: gcpHandlers["SourceBucketRepo"], - } + gcpHandler: gcpHandlers["SourceBucketRepo"], + } } func (repo *SourceBucketRepo) List(projectId string) (buckets []domain.Bucket, err error) { @@ -45,7 +45,7 @@ func (repo *SourceBucketRepo) UploadFile(fileName string) (success bool, err err func NewSinkBucketRepo(gcpHandlers map[string]GcpHandler) *SinkBucketRepo { return &SinkBucketRepo{ gcpHandlers: gcpHandlers, - gcpHandler: gcpHandlers["SinkBucketRepo"], + gcpHandler: gcpHandlers["SinkBucketRepo"], } } @@ -68,5 +68,3 @@ func (repo *SinkBucketRepo) UploadFile(fileName string) (success bool, err error func (repo *SinkBucketRepo) ListFileNamesToFetch(fileName string) (cloudFiles domain.CloudFiles, err error) { return cloudFiles, err } - - diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/impl.go_STOP b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/impl.go_STOP similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/impl.go_STOP rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/impl.go_STOP diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/interfaces_test/webservice_test.go b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/interfaces_test/webservice_test.go similarity index 87% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/interfaces_test/webservice_test.go rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/interfaces_test/webservice_test.go index c304a45..79cfc2d 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/interfaces_test/webservice_test.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/interfaces_test/webservice_test.go @@ -1,23 +1,24 @@ package interfaces_test import ( - . "interfaces" - . "utils" - "infrastructure" - "github.com/pkg/errors" + "04_onion/infrastructure" + . "04_onion/interfaces" + . "04_onion/utils" "io/ioutil" "net/http" "net/http/httptest" "os" "strings" "testing" + + "github.com/pkg/errors" ) const failure = "\u2717" const defaultFileName = "eventset1.jsonl" -var fileName string -var wsh WebserviceHandler +var fileName string +var wsh WebserviceHandler func init() { GetOptions() @@ -46,7 +47,7 @@ func init() { type endpoint struct { Api - expectedBody string + expectedBody string } func TestEndpoints(t *testing.T) { @@ -57,22 +58,22 @@ func TestEndpoints(t *testing.T) { "/health"}, `{"alive": true}`}, {Api{wsh.ListSourceBuckets, - "/list-source-buckets?projectId="+ Config.GcpSourceProjectId}, + "/list-source-buckets?projectId=" + Config.GcpSourceProjectId}, `{"buckets":[{"name":"lexttc3-my-backup-bucket"},{"name":"lexttc3-my-source-bucket"}]}`}, {Api{wsh.ListSinkBuckets, - "/list-sink-buckets?projectId="+ Config.GcpSinkProjectId}, + "/list-sink-buckets?projectId=" + Config.GcpSinkProjectId}, `{"buckets":[{"name":"lexttc3-my-backup-bucket"},{"name":"lexttc3-my-source-bucket"}]}`}, {Api{wsh.UploadFile, - "/upload-file?fileName="+fileName}, + "/upload-file?fileName=" + fileName}, `{"success":true}`}, //{Api{wsh.DownloadFile, // "/download-file?fileName="+fileName}, // `{"success":true}`}, {Api{wsh.SourceFileExists, - "/source-file-exists?fileName="+fileName}, + "/source-file-exists?fileName=" + fileName}, `{"exists":true}`}, {Api{wsh.LocalFileExists, - "/local-file-exists?fileName="+fileName}, + "/local-file-exists?fileName=" + fileName}, `{"exists":true}`}, } diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/localstorage.go b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/localstorage.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/localstorage.go rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/localstorage.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice.go b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice.go similarity index 96% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice.go rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice.go index ca2ce34..7b188a5 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice.go @@ -1,14 +1,14 @@ package interfaces import ( + "04_onion/domain" "io" "net/http" - "domain" ) type Api struct { - Handler func(res http.ResponseWriter, req *http.Request) - Url string + Handler func(res http.ResponseWriter, req *http.Request) + Url string } type LocalInteractor interface { diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice_helpers.go b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice_helpers.go similarity index 92% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice_helpers.go rename to 2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice_helpers.go index dc7a7d8..046e650 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/interfaces/webservice_helpers.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/interfaces/webservice_helpers.go @@ -1,12 +1,13 @@ package interfaces import ( + "04_onion/domain" + . "04_onion/utils" "encoding/json" - "github.com/pkg/errors" - "net/http" "fmt" - "domain" - . "utils" + "net/http" + + "github.com/pkg/errors" ) var ErrorResponse = []byte("Error") @@ -44,13 +45,12 @@ func handleSuccess(debugMsg, msg string, req *http.Request, res http.ResponseWri output, err := setFormat(getFormat(req), response) if err != nil { output = ErrorResponse - Error.Printf("Failed to setFormat. %v", err) + Error.Printf("Failed to setFormat. %v", err) } Debug.Printf("string(output): %s", string(output)) fmt.Fprintln(res, string(output)) } - func handleExists(debugMsg, msg string, req *http.Request, res http.ResponseWriter, err error, exists bool) { Debug.Printf(debugMsg) response := domain.Existence{} @@ -61,7 +61,7 @@ func handleExists(debugMsg, msg string, req *http.Request, res http.ResponseWrit output, err := setFormat(getFormat(req), response) if err != nil { output = ErrorResponse - Error.Printf("Failed to setFormat. %v", err) + Error.Printf("Failed to setFormat. %v", err) } Debug.Printf("string(output): %s", string(output)) fmt.Fprintln(res, string(output)) @@ -80,15 +80,9 @@ func handleBuckets(debugMsg, msg string, req *http.Request, res http.ResponseWri output, err := setFormat(getFormat(req), response) if err != nil { output = ErrorResponse - Error.Printf("Failed to setFormat. %v", err) + Error.Printf("Failed to setFormat. %v", err) //return } Debug.Printf("string(output): %s", string(output)) fmt.Fprintln(res, string(output)) } - - - - - - diff --git a/2-design-patterns/ch06-onion-arch/04_onion/main.go b/2-design-patterns/ch06-onion-arch/04_onion/main.go index 23f7eae..a9f8fd2 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/main.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/main.go @@ -1,17 +1,19 @@ package main import ( - . "utils" - . "interfaces" - "os" + "04_onion/infrastructure" + . "04_onion/interfaces" + . "04_onion/utils" "io/ioutil" - "infrastructure" - "github.com/pkg/errors" "net/http" + "os" + + "github.com/pkg/errors" ) const defaultFileName = "eventset1.jsonl" -var fileName string + +var fileName string var wsh WebserviceHandler func init() { @@ -35,7 +37,7 @@ func init() { type endpoint struct { Api - uriExample string + uriExample string } func printApiExample(url, uriExample string) { @@ -58,12 +60,12 @@ func main() { var endpoints = []endpoint{ {Api{wsh.Health, "/health"}, ""}, - {Api{wsh.ListSourceBuckets, "/list-source-buckets"}, "projectId="+ Config.GcpSourceProjectId}, - {Api{wsh.ListSinkBuckets, "/list-sink-buckets"}, "projectId="+ Config.GcpSinkProjectId}, - {Api{wsh.SourceFileExists, "/source-file-exists"}, "fileName="+fileName}, - {Api{wsh.DownloadFile, "/download-file"}, "fileName="+fileName}, - {Api{wsh.UploadFile, "/upload-file"}, "fileName="+fileName}, - {Api{wsh.LocalFileExists, "/local-file-exists"}, "fileName="+fileName}, + {Api{wsh.ListSourceBuckets, "/list-source-buckets"}, "projectId=" + Config.GcpSourceProjectId}, + {Api{wsh.ListSinkBuckets, "/list-sink-buckets"}, "projectId=" + Config.GcpSinkProjectId}, + {Api{wsh.SourceFileExists, "/source-file-exists"}, "fileName=" + fileName}, + {Api{wsh.DownloadFile, "/download-file"}, "fileName=" + fileName}, + {Api{wsh.UploadFile, "/upload-file"}, "fileName=" + fileName}, + {Api{wsh.LocalFileExists, "/local-file-exists"}, "fileName=" + fileName}, } Info.Println("Example API endpoints:") { diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/usecases/usecases.go b/2-design-patterns/ch06-onion-arch/04_onion/usecases/usecases.go similarity index 94% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/usecases/usecases.go rename to 2-design-patterns/ch06-onion-arch/04_onion/usecases/usecases.go index c58cac5..ca88160 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/usecases/usecases.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/usecases/usecases.go @@ -1,7 +1,7 @@ package usecases import ( - "domain" + "04_onion/domain" ) type LocalInteractor struct { @@ -14,7 +14,7 @@ func (interactor *LocalInteractor) LocalFileExists(fileName string) (fileExists type GcpInteractor struct { SourceBucketRepository domain.BucketRepository - SinkBucketRepository domain.BucketRepository + SinkBucketRepository domain.BucketRepository } func (interactor *GcpInteractor) ListSourceBuckets(projectId string) (buckets []domain.Bucket, err error) { diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/utils/logger.go b/2-design-patterns/ch06-onion-arch/04_onion/utils/logger.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/utils/logger.go rename to 2-design-patterns/ch06-onion-arch/04_onion/utils/logger.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/utils/options.go b/2-design-patterns/ch06-onion-arch/04_onion/utils/options.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/utils/options.go rename to 2-design-patterns/ch06-onion-arch/04_onion/utils/options.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/utils/utils.go b/2-design-patterns/ch06-onion-arch/04_onion/utils/utils.go similarity index 100% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/utils/utils.go rename to 2-design-patterns/ch06-onion-arch/04_onion/utils/utils.go diff --git a/2-design-patterns/ch06-onion-arch/04_onion/src/utils/utils_test/utils_test.go b/2-design-patterns/ch06-onion-arch/04_onion/utils/utils_test/utils_test.go similarity index 98% rename from 2-design-patterns/ch06-onion-arch/04_onion/src/utils/utils_test/utils_test.go rename to 2-design-patterns/ch06-onion-arch/04_onion/utils/utils_test/utils_test.go index dee4667..ebdc21c 100644 --- a/2-design-patterns/ch06-onion-arch/04_onion/src/utils/utils_test/utils_test.go +++ b/2-design-patterns/ch06-onion-arch/04_onion/utils/utils_test/utils_test.go @@ -1,10 +1,11 @@ package utils_test import ( + "04_onion/utils" + "os" "testing" - "utils" + "github.com/pkg/errors" - "os" ) func TestPanic(t *testing.T) { @@ -24,7 +25,6 @@ func TestPanic3(t *testing.T) { assertPanic(t, zeroPanicFcn) } - // ------------- // Helpers // ------------- diff --git a/3-functional-techniques/ch07-func-param/01_func_param/go.mod b/3-functional-techniques/ch07-func-param/01_func_param/go.mod new file mode 100644 index 0000000..8adc109 --- /dev/null +++ b/3-functional-techniques/ch07-func-param/01_func_param/go.mod @@ -0,0 +1,11 @@ +module 01_func_param + +go 1.18 + +require ( + github.com/BurntSushi/toml v1.1.0 + github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.8.1 +) + +require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect diff --git a/3-functional-techniques/ch07-func-param/01_func_param/go.sum b/3-functional-techniques/ch07-func-param/01_func_param/go.sum new file mode 100644 index 0000000..e70b169 --- /dev/null +++ b/3-functional-techniques/ch07-func-param/01_func_param/go.sum @@ -0,0 +1,14 @@ +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/3-functional-techniques/ch07-func-param/01_func_param/init b/3-functional-techniques/ch07-func-param/01_func_param/init deleted file mode 100644 index 2f6a36c..0000000 --- a/3-functional-techniques/ch07-func-param/01_func_param/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/3-functional-techniques/ch07-func-param/01_func_param/init-windows.sh b/3-functional-techniques/ch07-func-param/01_func_param/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/3-functional-techniques/ch07-func-param/01_func_param/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/3-functional-techniques/ch07-func-param/01_func_param/main.go b/3-functional-techniques/ch07-func-param/01_func_param/main.go index 3ddd572..b71e322 100644 --- a/3-functional-techniques/ch07-func-param/01_func_param/main.go +++ b/3-functional-techniques/ch07-func-param/01_func_param/main.go @@ -1,15 +1,15 @@ package main import ( - "server" - . "utils" + "01_func_param/server" + . "01_func_param/utils" "context" + "fmt" "io/ioutil" "net/http" "os" "os/signal" "time" - "fmt" ) func init() { @@ -25,7 +25,7 @@ func main() { server.MaxConcurrentConnections(4), server.MaxNumber(256), // Config.MaxNumber server.UseNumberHandler(true), - server.FormatNumber(func(x int) (string, error) { return fmt.Sprintf("%x", x), nil }), // anonymous fcn + server.FormatNumber(func(x int) (string, error) { return fmt.Sprintf("%x", x), nil }), // anonymous fcn //server.FormatNumber(func(x int) (string, error) { return fmt.Sprintf("%b", x), nil }), // anonymous fcn //server.FormatNumber(func(x int) (string, error) { return "", errors.New("FormatNumber error") }), // anonymous fcn ) @@ -34,20 +34,20 @@ func main() { os.Exit(1) } srv := &http.Server{ - Addr: ":"+ Config.Port, + Addr: ":" + Config.Port, Handler: newServer, } go func() { <-quit - ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(2 * time.Second)) + ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(2*time.Second)) defer cancel() Info.Println("shutting down server...") - if err := srv.Shutdown( ctx ); err != nil { + if err := srv.Shutdown(ctx); err != nil { Error.Printf("unable to shutdown server: %v", err) } }() - Error.Println("server started at localhost:"+ Config.Port) + Error.Println("server started at localhost:" + Config.Port) err = srv.ListenAndServe() if err != nil && err != http.ErrServerClosed { Error.Printf("ListenAndServe error: %v", err) diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/server/server.go b/3-functional-techniques/ch07-func-param/01_func_param/server/server.go similarity index 100% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/server/server.go rename to 3-functional-techniques/ch07-func-param/01_func_param/server/server.go diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/server/server_options.go b/3-functional-techniques/ch07-func-param/01_func_param/server/server_options.go similarity index 92% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/server/server_options.go rename to 3-functional-techniques/ch07-func-param/01_func_param/server/server_options.go index 3c76995..6c41b2c 100644 --- a/3-functional-techniques/ch07-func-param/01_func_param/src/server/server_options.go +++ b/3-functional-techniques/ch07-func-param/01_func_param/server/server_options.go @@ -1,7 +1,7 @@ package server import ( - . "utils" + . "01_func_param/utils" "errors" ) @@ -34,9 +34,8 @@ func FormatNumber(fn convert) ServerOption { } func UseNumberHandler(b bool) ServerOption { - return func(o *options) error { + return func(o *options) error { o.useNumberHandler = b return nil } } - diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/utils/logger.go b/3-functional-techniques/ch07-func-param/01_func_param/utils/logger.go similarity index 100% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/utils/logger.go rename to 3-functional-techniques/ch07-func-param/01_func_param/utils/logger.go diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/utils/options.go b/3-functional-techniques/ch07-func-param/01_func_param/utils/options.go similarity index 100% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/utils/options.go rename to 3-functional-techniques/ch07-func-param/01_func_param/utils/options.go diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/utils/utils.go b/3-functional-techniques/ch07-func-param/01_func_param/utils/utils.go similarity index 100% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/utils/utils.go rename to 3-functional-techniques/ch07-func-param/01_func_param/utils/utils.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/utils/utils_test/utils_test.go b/3-functional-techniques/ch07-func-param/01_func_param/utils/utils_test/utils_test.go similarity index 97% rename from 4-purely-functional/ch10-monads/01_car_steps/src/utils/utils_test/utils_test.go rename to 3-functional-techniques/ch07-func-param/01_func_param/utils/utils_test/utils_test.go index dee4667..761410c 100644 --- a/4-purely-functional/ch10-monads/01_car_steps/src/utils/utils_test/utils_test.go +++ b/3-functional-techniques/ch07-func-param/01_func_param/utils/utils_test/utils_test.go @@ -1,10 +1,11 @@ package utils_test import ( + "01_func_param/utils" + "os" "testing" - "utils" + "github.com/pkg/errors" - "os" ) func TestPanic(t *testing.T) { @@ -24,7 +25,6 @@ func TestPanic3(t *testing.T) { assertPanic(t, zeroPanicFcn) } - // ------------- // Helpers // ------------- diff --git a/3-functional-techniques/ch08-pipelining/01_imperative/go.mod b/3-functional-techniques/ch08-pipelining/01_imperative/go.mod new file mode 100644 index 0000000..a557ea6 --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/01_imperative/go.mod @@ -0,0 +1,3 @@ +module 01_imperative + +go 1.18 diff --git a/3-functional-techniques/ch08-pipelining/01_imperative/init b/3-functional-techniques/ch08-pipelining/01_imperative/init deleted file mode 100644 index 2f6a36c..0000000 --- a/3-functional-techniques/ch08-pipelining/01_imperative/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/3-functional-techniques/ch08-pipelining/01_imperative/init-windows.sh b/3-functional-techniques/ch08-pipelining/01_imperative/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/3-functional-techniques/ch08-pipelining/01_imperative/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/3-functional-techniques/ch08-pipelining/02_concurrent/go.mod b/3-functional-techniques/ch08-pipelining/02_concurrent/go.mod new file mode 100644 index 0000000..c7afe67 --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/02_concurrent/go.mod @@ -0,0 +1,3 @@ +module 02_concurrent + +go 1.18 diff --git a/3-functional-techniques/ch08-pipelining/02_concurrent/init b/3-functional-techniques/ch08-pipelining/02_concurrent/init deleted file mode 100644 index 2f6a36c..0000000 --- a/3-functional-techniques/ch08-pipelining/02_concurrent/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/3-functional-techniques/ch08-pipelining/02_concurrent/init-windows.sh b/3-functional-techniques/ch08-pipelining/02_concurrent/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/3-functional-techniques/ch08-pipelining/02_concurrent/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/3-functional-techniques/ch08-pipelining/03_buffered/go.mod b/3-functional-techniques/ch08-pipelining/03_buffered/go.mod new file mode 100644 index 0000000..6cbefb7 --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/03_buffered/go.mod @@ -0,0 +1,3 @@ +module 03_buffered + +go 1.18 diff --git a/3-functional-techniques/ch08-pipelining/03_buffered/init b/3-functional-techniques/ch08-pipelining/03_buffered/init deleted file mode 100644 index 2f6a36c..0000000 --- a/3-functional-techniques/ch08-pipelining/03_buffered/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/3-functional-techniques/ch08-pipelining/03_buffered/init-windows.sh b/3-functional-techniques/ch08-pipelining/03_buffered/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/3-functional-techniques/ch08-pipelining/03_buffered/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/3-functional-techniques/ch08-pipelining/04_buffered_cpus/go.mod b/3-functional-techniques/ch08-pipelining/04_buffered_cpus/go.mod new file mode 100644 index 0000000..b21ef11 --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/04_buffered_cpus/go.mod @@ -0,0 +1,3 @@ +module 04_buffered_cpus + +go 1.18 diff --git a/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init b/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init deleted file mode 100644 index 2f6a36c..0000000 --- a/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init-windows.sh b/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/3-functional-techniques/ch08-pipelining/04_buffered_cpus/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/3-functional-techniques/ch08-pipelining/go.mod b/3-functional-techniques/ch08-pipelining/go.mod new file mode 100644 index 0000000..615936d --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/go.mod @@ -0,0 +1,13 @@ +module ch08-pipelining + +go 1.18 + +require ( + github.com/go-goodies/go_currency v0.0.0-20140912185802-bf5e29957fc4 + github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88 +) + +require ( + github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24 // indirect + github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect +) diff --git a/3-functional-techniques/ch08-pipelining/go.sum b/3-functional-techniques/ch08-pipelining/go.sum new file mode 100644 index 0000000..42aa744 --- /dev/null +++ b/3-functional-techniques/ch08-pipelining/go.sum @@ -0,0 +1,8 @@ +github.com/go-goodies/go_currency v0.0.0-20140912185802-bf5e29957fc4 h1:P5rBQJX1qYsOQAUNmfxZgdQ95PmNN84oPZGV+qyt5TY= +github.com/go-goodies/go_currency v0.0.0-20140912185802-bf5e29957fc4/go.mod h1:tYX6HE9PE4A+3Pdu4WkjizG48TfbgNo3dQxfpStU7EE= +github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88 h1:5qQuBTdiv/UA3rxhsjzVYehlFUCp6ODhujqQ+u+0Byo= +github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88/go.mod h1:iy2EooSaoOajMrw5Ynl8JOTVPPpvy51tVxzNbiuEQf0= +github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24 h1:xLD2c01e4ZJD9QoUINYfN2QRlBsKuxduzKtpk8oVjo0= +github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24/go.mod h1:htqcqoNQp32xb0kCqp6zLqMIqg66TiAtr52L2ydpER4= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= diff --git a/4-purely-functional/ch09-functor-monoid/01_clock_functor/src/functor/clock.go b/4-purely-functional/ch09-functor-monoid/01_clock_functor/functor/clock.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/01_clock_functor/src/functor/clock.go rename to 4-purely-functional/ch09-functor-monoid/01_clock_functor/functor/clock.go diff --git a/4-purely-functional/ch09-functor-monoid/01_clock_functor/go.mod b/4-purely-functional/ch09-functor-monoid/01_clock_functor/go.mod new file mode 100644 index 0000000..423efbc --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/01_clock_functor/go.mod @@ -0,0 +1,3 @@ +module 01_clock_functor + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/01_clock_functor/init b/4-purely-functional/ch09-functor-monoid/01_clock_functor/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/01_clock_functor/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/01_clock_functor/init-windows.sh b/4-purely-functional/ch09-functor-monoid/01_clock_functor/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/01_clock_functor/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/01_clock_functor/main.go b/4-purely-functional/ch09-functor-monoid/01_clock_functor/main.go index b1e7c41..1c32d21 100644 --- a/4-purely-functional/ch09-functor-monoid/01_clock_functor/main.go +++ b/4-purely-functional/ch09-functor-monoid/01_clock_functor/main.go @@ -2,9 +2,9 @@ package main import ( "log" - "functor" -) + "01_clock_functor/functor" +) func main() { @@ -26,4 +26,3 @@ func main() { log.Printf("chain applications: %s", functor.Wrap([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}).Map(amPmMapper)) } - diff --git a/4-purely-functional/ch09-functor-monoid/01_no_generics_nums/go.mod b/4-purely-functional/ch09-functor-monoid/01_no_generics_nums/go.mod new file mode 100644 index 0000000..4469eca --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/01_no_generics_nums/go.mod @@ -0,0 +1,3 @@ +module 01_no_generics_nums + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/src/car/car_slice.go b/4-purely-functional/ch09-functor-monoid/02_generics_cars/car/car_slice.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/02_generics_cars/src/car/car_slice.go rename to 4-purely-functional/ch09-functor-monoid/02_generics_cars/car/car_slice.go diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/src/car/types.go b/4-purely-functional/ch09-functor-monoid/02_generics_cars/car/types.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/02_generics_cars/src/car/types.go rename to 4-purely-functional/ch09-functor-monoid/02_generics_cars/car/types.go diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/go.mod b/4-purely-functional/ch09-functor-monoid/02_generics_cars/go.mod new file mode 100644 index 0000000..dc45ae5 --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/02_generics_cars/go.mod @@ -0,0 +1,3 @@ +module 02_generics_cars + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/init b/4-purely-functional/ch09-functor-monoid/02_generics_cars/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/02_generics_cars/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/init-windows.sh b/4-purely-functional/ch09-functor-monoid/02_generics_cars/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/02_generics_cars/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/02_generics_cars/main.go b/4-purely-functional/ch09-functor-monoid/02_generics_cars/main.go index ec64f39..10eb586 100644 --- a/4-purely-functional/ch09-functor-monoid/02_generics_cars/main.go +++ b/4-purely-functional/ch09-functor-monoid/02_generics_cars/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "car" + . "03_generics_car/car" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/go.mod b/4-purely-functional/ch09-functor-monoid/03_generics_nums/go.mod new file mode 100644 index 0000000..68e8170 --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/03_generics_nums/go.mod @@ -0,0 +1,3 @@ +module 03_generics_nums + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/init b/4-purely-functional/ch09-functor-monoid/03_generics_nums/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/03_generics_nums/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/init-windows.sh b/4-purely-functional/ch09-functor-monoid/03_generics_nums/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/03_generics_nums/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/main.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/main.go index f2d7314..627c27d 100644 --- a/4-purely-functional/ch09-functor-monoid/03_generics_nums/main.go +++ b/4-purely-functional/ch09-functor-monoid/03_generics_nums/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "num" + . "03_generics_num/num" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/complex128_slice.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/complex128_slice.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/complex128_slice.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/complex128_slice.go diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/float64_slice.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/float64_slice.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/float64_slice.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/float64_slice.go diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/int32_slice.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/int32_slice.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/int32_slice.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/int32_slice.go diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/int8_slice.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/int8_slice.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/int8_slice.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/int8_slice.go diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/types.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/types.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/types.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/types.go diff --git a/4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/vars.go b/4-purely-functional/ch09-functor-monoid/03_generics_nums/num/vars.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/03_generics_nums/src/num/vars.go rename to 4-purely-functional/ch09-functor-monoid/03_generics_nums/num/vars.go diff --git a/4-purely-functional/ch09-functor-monoid/05_int_functor/src/functor/ints.go b/4-purely-functional/ch09-functor-monoid/05_int_functor/functor/ints.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/05_int_functor/src/functor/ints.go rename to 4-purely-functional/ch09-functor-monoid/05_int_functor/functor/ints.go diff --git a/4-purely-functional/ch09-functor-monoid/05_int_functor/go.mod b/4-purely-functional/ch09-functor-monoid/05_int_functor/go.mod new file mode 100644 index 0000000..566a835 --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/05_int_functor/go.mod @@ -0,0 +1,3 @@ +module 05_int_functor + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/05_int_functor/init b/4-purely-functional/ch09-functor-monoid/05_int_functor/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/05_int_functor/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/05_int_functor/init-windows.sh b/4-purely-functional/ch09-functor-monoid/05_int_functor/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/05_int_functor/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/05_int_functor/main.go b/4-purely-functional/ch09-functor-monoid/05_int_functor/main.go index 65727ac..f5deaad 100644 --- a/4-purely-functional/ch09-functor-monoid/05_int_functor/main.go +++ b/4-purely-functional/ch09-functor-monoid/05_int_functor/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "functor" + . "05_int_functor/functor" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/06_compose/src/compose/compose.go b/4-purely-functional/ch09-functor-monoid/06_compose/compose/compose.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/06_compose/src/compose/compose.go rename to 4-purely-functional/ch09-functor-monoid/06_compose/compose/compose.go diff --git a/4-purely-functional/ch09-functor-monoid/06_compose/go.mod b/4-purely-functional/ch09-functor-monoid/06_compose/go.mod new file mode 100644 index 0000000..7bf3ada --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/06_compose/go.mod @@ -0,0 +1,3 @@ +module 06_compose + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/06_compose/init b/4-purely-functional/ch09-functor-monoid/06_compose/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/06_compose/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/06_compose/init-windows.sh b/4-purely-functional/ch09-functor-monoid/06_compose/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/06_compose/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/06_compose/main.go b/4-purely-functional/ch09-functor-monoid/06_compose/main.go index 878e59b..afba94f 100644 --- a/4-purely-functional/ch09-functor-monoid/06_compose/main.go +++ b/4-purely-functional/ch09-functor-monoid/06_compose/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "compose" + . "06_compose/compose" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/07_compose_gof/src/compose/compose.go b/4-purely-functional/ch09-functor-monoid/07_compose_gof/compose/compose.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/07_compose_gof/src/compose/compose.go rename to 4-purely-functional/ch09-functor-monoid/07_compose_gof/compose/compose.go diff --git a/4-purely-functional/ch09-functor-monoid/07_compose_gof/go.mod b/4-purely-functional/ch09-functor-monoid/07_compose_gof/go.mod new file mode 100644 index 0000000..52b7e59 --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/07_compose_gof/go.mod @@ -0,0 +1,3 @@ +module 07_compose_gof + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/07_compose_gof/init b/4-purely-functional/ch09-functor-monoid/07_compose_gof/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/07_compose_gof/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/07_compose_gof/init-windows.sh b/4-purely-functional/ch09-functor-monoid/07_compose_gof/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/07_compose_gof/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/07_compose_gof/main.go b/4-purely-functional/ch09-functor-monoid/07_compose_gof/main.go index c979026..c8f4f29 100644 --- a/4-purely-functional/ch09-functor-monoid/07_compose_gof/main.go +++ b/4-purely-functional/ch09-functor-monoid/07_compose_gof/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "compose" + . "07_compose_gof/compose" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/08_compose_fog/src/compose/compose.go b/4-purely-functional/ch09-functor-monoid/08_compose_fog/compose/compose.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/08_compose_fog/src/compose/compose.go rename to 4-purely-functional/ch09-functor-monoid/08_compose_fog/compose/compose.go diff --git a/4-purely-functional/ch09-functor-monoid/08_compose_fog/go.mod b/4-purely-functional/ch09-functor-monoid/08_compose_fog/go.mod new file mode 100644 index 0000000..0ab0b22 --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/08_compose_fog/go.mod @@ -0,0 +1,3 @@ +module 08_compose_fog + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/08_compose_fog/init b/4-purely-functional/ch09-functor-monoid/08_compose_fog/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/08_compose_fog/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/08_compose_fog/init-windows.sh b/4-purely-functional/ch09-functor-monoid/08_compose_fog/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/08_compose_fog/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/08_compose_fog/main.go b/4-purely-functional/ch09-functor-monoid/08_compose_fog/main.go index b654eb8..734e62e 100644 --- a/4-purely-functional/ch09-functor-monoid/08_compose_fog/main.go +++ b/4-purely-functional/ch09-functor-monoid/08_compose_fog/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - . "compose" + . "08_compose_fog/compose" ) func main() { diff --git a/4-purely-functional/ch09-functor-monoid/09_clock_functor/src/functor/clock.go b/4-purely-functional/ch09-functor-monoid/09_clock_functor/functor/clock.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/09_clock_functor/src/functor/clock.go rename to 4-purely-functional/ch09-functor-monoid/09_clock_functor/functor/clock.go diff --git a/4-purely-functional/ch09-functor-monoid/09_clock_functor/go.mod b/4-purely-functional/ch09-functor-monoid/09_clock_functor/go.mod new file mode 100644 index 0000000..c7b033d --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/09_clock_functor/go.mod @@ -0,0 +1,3 @@ +module 09_clock_functor + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/09_clock_functor/init b/4-purely-functional/ch09-functor-monoid/09_clock_functor/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/09_clock_functor/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/09_clock_functor/init-windows.sh b/4-purely-functional/ch09-functor-monoid/09_clock_functor/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/09_clock_functor/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/09_clock_functor/main.go b/4-purely-functional/ch09-functor-monoid/09_clock_functor/main.go index 458a45d..59e0f1a 100644 --- a/4-purely-functional/ch09-functor-monoid/09_clock_functor/main.go +++ b/4-purely-functional/ch09-functor-monoid/09_clock_functor/main.go @@ -1,7 +1,7 @@ package main import ( - . "functor" + . "09_clock_functor/functor" "fmt" ) diff --git a/4-purely-functional/ch09-functor-monoid/10_car_functor/src/functor/car.go b/4-purely-functional/ch09-functor-monoid/10_car_functor/functor/car.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/10_car_functor/src/functor/car.go rename to 4-purely-functional/ch09-functor-monoid/10_car_functor/functor/car.go diff --git a/4-purely-functional/ch09-functor-monoid/10_car_functor/go.mod b/4-purely-functional/ch09-functor-monoid/10_car_functor/go.mod new file mode 100644 index 0000000..1695b6f --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/10_car_functor/go.mod @@ -0,0 +1,3 @@ +module 10_car_functor + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/10_car_functor/init b/4-purely-functional/ch09-functor-monoid/10_car_functor/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/10_car_functor/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/10_car_functor/init-windows.sh b/4-purely-functional/ch09-functor-monoid/10_car_functor/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/10_car_functor/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/10_car_functor/main.go b/4-purely-functional/ch09-functor-monoid/10_car_functor/main.go index 1c03dc4..681cbcb 100644 --- a/4-purely-functional/ch09-functor-monoid/10_car_functor/main.go +++ b/4-purely-functional/ch09-functor-monoid/10_car_functor/main.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "functor" + "10_car_functor/functor" "strings" ) diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/go.mod b/4-purely-functional/ch09-functor-monoid/11_monoid/go.mod new file mode 100644 index 0000000..d7df2ff --- /dev/null +++ b/4-purely-functional/ch09-functor-monoid/11_monoid/go.mod @@ -0,0 +1,3 @@ +module 11_monoid + +go 1.18 diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/init b/4-purely-functional/ch09-functor-monoid/11_monoid/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch09-functor-monoid/11_monoid/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/init-windows.sh b/4-purely-functional/ch09-functor-monoid/11_monoid/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch09-functor-monoid/11_monoid/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/main.go b/4-purely-functional/ch09-functor-monoid/11_monoid/main.go index bd42e9a..ddade32 100644 --- a/4-purely-functional/ch09-functor-monoid/11_monoid/main.go +++ b/4-purely-functional/ch09-functor-monoid/11_monoid/main.go @@ -1,7 +1,7 @@ package main import ( - "monoid" + "11_monoid/monoid" "fmt" ) diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/README.md b/4-purely-functional/ch09-functor-monoid/11_monoid/monoid/README.md similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/README.md rename to 4-purely-functional/ch09-functor-monoid/11_monoid/monoid/README.md diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/int_monoid.go b/4-purely-functional/ch09-functor-monoid/11_monoid/monoid/int_monoid.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/int_monoid.go rename to 4-purely-functional/ch09-functor-monoid/11_monoid/monoid/int_monoid.go diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/lineitem_monoid.go b/4-purely-functional/ch09-functor-monoid/11_monoid/monoid/lineitem_monoid.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/lineitem_monoid.go rename to 4-purely-functional/ch09-functor-monoid/11_monoid/monoid/lineitem_monoid.go diff --git a/4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/name_monoid.go b/4-purely-functional/ch09-functor-monoid/11_monoid/monoid/name_monoid.go similarity index 100% rename from 4-purely-functional/ch09-functor-monoid/11_monoid/src/monoid/name_monoid.go rename to 4-purely-functional/ch09-functor-monoid/11_monoid/monoid/name_monoid.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/go.mod b/4-purely-functional/ch10-monads/01_car_steps/go.mod new file mode 100644 index 0000000..0cbbeed --- /dev/null +++ b/4-purely-functional/ch10-monads/01_car_steps/go.mod @@ -0,0 +1,11 @@ +module 01_car_steps + +go 1.18 + +require ( + github.com/BurntSushi/toml v1.1.0 + github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.8.1 +) + +require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect diff --git a/4-purely-functional/ch10-monads/01_car_steps/go.sum b/4-purely-functional/ch10-monads/01_car_steps/go.sum new file mode 100644 index 0000000..e70b169 --- /dev/null +++ b/4-purely-functional/ch10-monads/01_car_steps/go.sum @@ -0,0 +1,14 @@ +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/4-purely-functional/ch10-monads/01_car_steps/init b/4-purely-functional/ch10-monads/01_car_steps/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch10-monads/01_car_steps/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch10-monads/01_car_steps/init-windows.sh b/4-purely-functional/ch10-monads/01_car_steps/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch10-monads/01_car_steps/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch10-monads/01_car_steps/main.go b/4-purely-functional/ch10-monads/01_car_steps/main.go index d09681a..4c3b1f2 100644 --- a/4-purely-functional/ch10-monads/01_car_steps/main.go +++ b/4-purely-functional/ch10-monads/01_car_steps/main.go @@ -1,8 +1,8 @@ package main import ( - "workflow" - . "utils" + . "01_car_steps/utils" + "01_car_steps/workflow" "bufio" "os" ) @@ -16,25 +16,24 @@ func init() { func main() { carCntr := 0 if file, err := os.Open(Config.DataFilepath); err == nil { - defer file.Close() + defer file.Close() Info.Println("----") - scanner := bufio.NewScanner(file) - for scanner.Scan() { - carCntr += 1 + scanner := bufio.NewScanner(file) + for scanner.Scan() { + carCntr += 1 Info.Println("Processing car #", carCntr) - line := scanner.Text() - Info.Println("IN :", line) - err, carJson := workflow.ProcessCar(line) - if err == nil { + line := scanner.Text() + Info.Println("IN :", line) + err, carJson := workflow.ProcessCar(line) + if err == nil { Info.Println("OUT:", carJson) } Info.Println("----") - } - if err = scanner.Err(); err != nil { + } + if err = scanner.Err(); err != nil { Error.Error(err) - } + } } else { Error.Error(err) } } - diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/utils/logger.go b/4-purely-functional/ch10-monads/01_car_steps/utils/logger.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/utils/logger.go rename to 4-purely-functional/ch10-monads/01_car_steps/utils/logger.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/utils/options.go b/4-purely-functional/ch10-monads/01_car_steps/utils/options.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/utils/options.go rename to 4-purely-functional/ch10-monads/01_car_steps/utils/options.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/utils/utils.go b/4-purely-functional/ch10-monads/01_car_steps/utils/utils.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/utils/utils.go rename to 4-purely-functional/ch10-monads/01_car_steps/utils/utils.go diff --git a/3-functional-techniques/ch07-func-param/01_func_param/src/utils/utils_test/utils_test.go b/4-purely-functional/ch10-monads/01_car_steps/utils/utils_test/utils_test.go similarity index 97% rename from 3-functional-techniques/ch07-func-param/01_func_param/src/utils/utils_test/utils_test.go rename to 4-purely-functional/ch10-monads/01_car_steps/utils/utils_test/utils_test.go index dee4667..ac07df5 100644 --- a/3-functional-techniques/ch07-func-param/01_func_param/src/utils/utils_test/utils_test.go +++ b/4-purely-functional/ch10-monads/01_car_steps/utils/utils_test/utils_test.go @@ -1,10 +1,11 @@ package utils_test import ( + "01_car_steps/utils" + "os" "testing" - "utils" + "github.com/pkg/errors" - "os" ) func TestPanic(t *testing.T) { @@ -24,7 +25,6 @@ func TestPanic3(t *testing.T) { assertPanic(t, zeroPanicFcn) } - // ------------- // Helpers // ------------- diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/workflow/car_types.go b/4-purely-functional/ch10-monads/01_car_steps/workflow/car_types.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/workflow/car_types.go rename to 4-purely-functional/ch10-monads/01_car_steps/workflow/car_types.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/workflow/monad.go b/4-purely-functional/ch10-monads/01_car_steps/workflow/monad.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/workflow/monad.go rename to 4-purely-functional/ch10-monads/01_car_steps/workflow/monad.go diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/workflow/process_car_steps.go b/4-purely-functional/ch10-monads/01_car_steps/workflow/process_car_steps.go similarity index 93% rename from 4-purely-functional/ch10-monads/01_car_steps/src/workflow/process_car_steps.go rename to 4-purely-functional/ch10-monads/01_car_steps/workflow/process_car_steps.go index e4ef61c..9d583ea 100644 --- a/4-purely-functional/ch10-monads/01_car_steps/src/workflow/process_car_steps.go +++ b/4-purely-functional/ch10-monads/01_car_steps/workflow/process_car_steps.go @@ -1,7 +1,7 @@ package workflow import ( - . "utils" + . "01_car_steps/utils" ) func ProcessCar(lineBase64 string) (err error, carJson string) { diff --git a/4-purely-functional/ch10-monads/01_car_steps/src/workflow/toolbox.go b/4-purely-functional/ch10-monads/01_car_steps/workflow/toolbox.go similarity index 100% rename from 4-purely-functional/ch10-monads/01_car_steps/src/workflow/toolbox.go rename to 4-purely-functional/ch10-monads/01_car_steps/workflow/toolbox.go diff --git a/4-purely-functional/ch10-monads/02_error_checker/go.mod b/4-purely-functional/ch10-monads/02_error_checker/go.mod new file mode 100644 index 0000000..e5e5b1c --- /dev/null +++ b/4-purely-functional/ch10-monads/02_error_checker/go.mod @@ -0,0 +1,3 @@ +module 02_error_checker + +go 1.18 diff --git a/4-purely-functional/ch10-monads/02_error_checker/init b/4-purely-functional/ch10-monads/02_error_checker/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch10-monads/02_error_checker/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch10-monads/02_error_checker/init-windows.sh b/4-purely-functional/ch10-monads/02_error_checker/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch10-monads/02_error_checker/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch10-monads/03_y_combinator/go.mod b/4-purely-functional/ch10-monads/03_y_combinator/go.mod new file mode 100644 index 0000000..c8b8c60 --- /dev/null +++ b/4-purely-functional/ch10-monads/03_y_combinator/go.mod @@ -0,0 +1,3 @@ +module 03_y_combinator + +go 1.18 diff --git a/4-purely-functional/ch10-monads/03_y_combinator/init b/4-purely-functional/ch10-monads/03_y_combinator/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch10-monads/03_y_combinator/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch10-monads/03_y_combinator/init-windows.sh b/4-purely-functional/ch10-monads/03_y_combinator/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch10-monads/03_y_combinator/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch10-monads/04_i18n/go.mod b/4-purely-functional/ch10-monads/04_i18n/go.mod new file mode 100644 index 0000000..c64b21b --- /dev/null +++ b/4-purely-functional/ch10-monads/04_i18n/go.mod @@ -0,0 +1,12 @@ +module 04_i18n + +go 1.18 + +require github.com/nicksnyder/go-i18n v1.10.1 + +require ( + github.com/BurntSushi/toml v1.1.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pelletier/go-toml v1.2.0 // indirect + gopkg.in/yaml.v2 v2.2.1 // indirect +) diff --git a/4-purely-functional/ch10-monads/04_i18n/go.sum b/4-purely-functional/ch10-monads/04_i18n/go.sum new file mode 100644 index 0000000..89cafa8 --- /dev/null +++ b/4-purely-functional/ch10-monads/04_i18n/go.sum @@ -0,0 +1,12 @@ +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/nicksnyder/go-i18n v1.10.1 h1:isfg77E/aCD7+0lD/D00ebR2MV5vgeQ276WYyDaCRQc= +github.com/nicksnyder/go-i18n v1.10.1/go.mod h1:e4Di5xjP9oTVrC6y3C7C0HoSYXjSbhh/dU0eUV32nB4= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/4-purely-functional/ch10-monads/04_i18n/src/i18n/errors.go b/4-purely-functional/ch10-monads/04_i18n/i18n/errors.go similarity index 100% rename from 4-purely-functional/ch10-monads/04_i18n/src/i18n/errors.go rename to 4-purely-functional/ch10-monads/04_i18n/i18n/errors.go diff --git a/4-purely-functional/ch10-monads/04_i18n/init b/4-purely-functional/ch10-monads/04_i18n/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch10-monads/04_i18n/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch10-monads/04_i18n/init-windows.sh b/4-purely-functional/ch10-monads/04_i18n/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch10-monads/04_i18n/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch10-monads/05_typeclasss/go.mod b/4-purely-functional/ch10-monads/05_typeclasss/go.mod new file mode 100644 index 0000000..fa68c36 --- /dev/null +++ b/4-purely-functional/ch10-monads/05_typeclasss/go.mod @@ -0,0 +1,3 @@ +module 05_typeclasss + +go 1.18 diff --git a/4-purely-functional/ch10-monads/05_typeclasss/init b/4-purely-functional/ch10-monads/05_typeclasss/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch10-monads/05_typeclasss/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch10-monads/05_typeclasss/init-windows.sh b/4-purely-functional/ch10-monads/05_typeclasss/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch10-monads/05_typeclasss/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch10-monads/05_typeclasss/main.go b/4-purely-functional/ch10-monads/05_typeclasss/main.go index a4917d4..854db4c 100644 --- a/4-purely-functional/ch10-monads/05_typeclasss/main.go +++ b/4-purely-functional/ch10-monads/05_typeclasss/main.go @@ -1,26 +1,26 @@ package main import ( - "typeclass" - "fmt" + "05_typeclasss/typeclass" + "fmt" ) func main() { - int42 := typeclass.Int(42) - str42 := typeclass.String("42") - fmt.Println("str42.Equals(int42):", str42.Equals(int42)) + int42 := typeclass.Int(42) + str42 := typeclass.String("42") + fmt.Println("str42.Equals(int42):", str42.Equals(int42)) - int64One := typeclass.Int64(1) - int64Two := typeclass.Int64(2) - fmt.Println("int64Two.Sum(int64One):", int64Two.Sum(int64One)) + int64One := typeclass.Int64(1) + int64Two := typeclass.Int64(2) + fmt.Println("int64Two.Sum(int64One):", int64Two.Sum(int64One)) - int32One := typeclass.Int32(1) - fmt.Println("int32One.Sum(int64One):", int32One.Sum(int64One)) + int32One := typeclass.Int32(1) + fmt.Println("int32One.Sum(int64One):", int32One.Sum(int64One)) - float32Five := typeclass.Float32(5) - fmt.Println("int32One.Sum(int64One):", float32Five.Sum(int64One)) + float32Five := typeclass.Float32(5) + fmt.Println("int32One.Sum(int64One):", float32Five.Sum(int64One)) - int64Slice123 := typeclass.IntSlice([]int{1, 2, 3}) - int64Slice234 := typeclass.IntSlice([]int{2, 3, 4}) - fmt.Println("int64Slice123.Sum(int64Slice234):", int64Slice123.Sum(int64Slice234)) + int64Slice123 := typeclass.IntSlice([]int{1, 2, 3}) + int64Slice234 := typeclass.IntSlice([]int{2, 3, 4}) + fmt.Println("int64Slice123.Sum(int64Slice234):", int64Slice123.Sum(int64Slice234)) } diff --git a/4-purely-functional/ch10-monads/05_typeclasss/src/typeclass/equals.go b/4-purely-functional/ch10-monads/05_typeclasss/typeclass/equals.go similarity index 100% rename from 4-purely-functional/ch10-monads/05_typeclasss/src/typeclass/equals.go rename to 4-purely-functional/ch10-monads/05_typeclasss/typeclass/equals.go diff --git a/4-purely-functional/ch10-monads/05_typeclasss/src/typeclass/sum.go b/4-purely-functional/ch10-monads/05_typeclasss/typeclass/sum.go similarity index 100% rename from 4-purely-functional/ch10-monads/05_typeclasss/src/typeclass/sum.go rename to 4-purely-functional/ch10-monads/05_typeclasss/typeclass/sum.go diff --git a/4-purely-functional/ch11-category-theory/01_essense_of_iterator/go.mod b/4-purely-functional/ch11-category-theory/01_essense_of_iterator/go.mod new file mode 100644 index 0000000..a7bde96 --- /dev/null +++ b/4-purely-functional/ch11-category-theory/01_essense_of_iterator/go.mod @@ -0,0 +1,3 @@ +module 01_essense_of_iterator + +go 1.18 diff --git a/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init b/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init deleted file mode 100644 index 2f6a36c..0000000 --- a/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init-windows.sh b/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/4-purely-functional/ch11-category-theory/01_essense_of_iterator/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/4-purely-functional/ch11-category-theory/02_anonymous/go.mod b/4-purely-functional/ch11-category-theory/02_anonymous/go.mod new file mode 100644 index 0000000..ff2019d --- /dev/null +++ b/4-purely-functional/ch11-category-theory/02_anonymous/go.mod @@ -0,0 +1,3 @@ +module 02_anonymous + +go 1.18 diff --git a/4-purely-functional/ch11-category-theory/03_lambda/go.mod b/4-purely-functional/ch11-category-theory/03_lambda/go.mod new file mode 100644 index 0000000..8d387df --- /dev/null +++ b/4-purely-functional/ch11-category-theory/03_lambda/go.mod @@ -0,0 +1,3 @@ +module 03_lambda + +go 1.18 diff --git a/4-purely-functional/ch11-category-theory/04_lambda/go.mod b/4-purely-functional/ch11-category-theory/04_lambda/go.mod new file mode 100644 index 0000000..f47d7e0 --- /dev/null +++ b/4-purely-functional/ch11-category-theory/04_lambda/go.mod @@ -0,0 +1,3 @@ +module 04_lambda + +go 1.18 diff --git a/4-purely-functional/ch11-category-theory/05_typeinferer/go.mod b/4-purely-functional/ch11-category-theory/05_typeinferer/go.mod new file mode 100644 index 0000000..1c1eaef --- /dev/null +++ b/4-purely-functional/ch11-category-theory/05_typeinferer/go.mod @@ -0,0 +1,3 @@ +module 05_typeinferer + +go 1.18 diff --git a/5-appendix/01_no-imports/go.mod b/5-appendix/01_no-imports/go.mod new file mode 100644 index 0000000..d67fd3b --- /dev/null +++ b/5-appendix/01_no-imports/go.mod @@ -0,0 +1,3 @@ +module 01_no-imports + +go 1.18 diff --git a/5-appendix/01_no-imports/init b/5-appendix/01_no-imports/init deleted file mode 100644 index 2f6a36c..0000000 --- a/5-appendix/01_no-imports/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/5-appendix/01_no-imports/init-windows.sh b/5-appendix/01_no-imports/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/5-appendix/01_no-imports/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/5-appendix/01_no-imports/main.go b/5-appendix/01_no-imports/main.go index fc4e995..78564c9 100644 --- a/5-appendix/01_no-imports/main.go +++ b/5-appendix/01_no-imports/main.go @@ -1,10 +1,9 @@ package main import ( - a "packagea" + a "01_no-imports/packagea" ) func main() { a.Atask() } - diff --git a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src/packagea/featurea.go b/5-appendix/01_no-imports/packagea/featurea.go similarity index 64% rename from 2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src/packagea/featurea.go rename to 5-appendix/01_no-imports/packagea/featurea.go index 40e0165..ea2b923 100644 --- a/2-design-patterns/ch06-onion-arch/01_dependency-rule-good/src/packagea/featurea.go +++ b/5-appendix/01_no-imports/packagea/featurea.go @@ -1,9 +1,8 @@ package packagea -import b "packageb" +import b "01_no-imports/packageb" func Atask() { println("A") b.Btask() } - diff --git a/5-appendix/01_no-imports/src/packageb/featureb.go b/5-appendix/01_no-imports/packageb/featureb.go similarity index 100% rename from 5-appendix/01_no-imports/src/packageb/featureb.go rename to 5-appendix/01_no-imports/packageb/featureb.go diff --git a/5-appendix/02_dependency-with-import/go.mod b/5-appendix/02_dependency-with-import/go.mod new file mode 100644 index 0000000..1c91c33 --- /dev/null +++ b/5-appendix/02_dependency-with-import/go.mod @@ -0,0 +1,3 @@ +module 02_dependency-with-import + +go 1.18 diff --git a/5-appendix/02_dependency-with-import/init b/5-appendix/02_dependency-with-import/init deleted file mode 100644 index 2f6a36c..0000000 --- a/5-appendix/02_dependency-with-import/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/5-appendix/02_dependency-with-import/init-windows.sh b/5-appendix/02_dependency-with-import/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/5-appendix/02_dependency-with-import/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/5-appendix/02_dependency-with-import/main.go b/5-appendix/02_dependency-with-import/main.go index fc4e995..139d0a7 100644 --- a/5-appendix/02_dependency-with-import/main.go +++ b/5-appendix/02_dependency-with-import/main.go @@ -1,10 +1,9 @@ package main import ( - a "packagea" + a "02_dependency-with-import/packagea" ) func main() { a.Atask() } - diff --git a/5-appendix/02_dependency-with-import/src/packagea/featurea.go b/5-appendix/02_dependency-with-import/packagea/featurea.go similarity index 67% rename from 5-appendix/02_dependency-with-import/src/packagea/featurea.go rename to 5-appendix/02_dependency-with-import/packagea/featurea.go index d63ab87..e3d092d 100644 --- a/5-appendix/02_dependency-with-import/src/packagea/featurea.go +++ b/5-appendix/02_dependency-with-import/packagea/featurea.go @@ -1,7 +1,7 @@ package packagea import ( - b "packageb" + b "02_dependency-with-import/packageb" "fmt" ) @@ -9,4 +9,3 @@ func Atask() { fmt.Println("A") b.Btask() } - diff --git a/5-appendix/02_dependency-with-import/src/packageb/featureb.go b/5-appendix/02_dependency-with-import/packageb/featureb.go similarity index 100% rename from 5-appendix/02_dependency-with-import/src/packageb/featureb.go rename to 5-appendix/02_dependency-with-import/packageb/featureb.go diff --git a/5-appendix/03_with-third-party-import/go.mod b/5-appendix/03_with-third-party-import/go.mod new file mode 100644 index 0000000..82632b6 --- /dev/null +++ b/5-appendix/03_with-third-party-import/go.mod @@ -0,0 +1,12 @@ +module 03_with-third-party-import + +go 1.18 + +require github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88 + +require ( + github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24 // indirect + github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect + github.com/remogatto/prettytest v0.0.0-20200211072524-6d385e11dcb8 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect +) diff --git a/5-appendix/03_with-third-party-import/go.sum b/5-appendix/03_with-third-party-import/go.sum new file mode 100644 index 0000000..1920f84 --- /dev/null +++ b/5-appendix/03_with-third-party-import/go.sum @@ -0,0 +1,15 @@ +github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88 h1:5qQuBTdiv/UA3rxhsjzVYehlFUCp6ODhujqQ+u+0Byo= +github.com/go-goodies/go_utils v0.0.0-20150622234138-8080b1735a88/go.mod h1:iy2EooSaoOajMrw5Ynl8JOTVPPpvy51tVxzNbiuEQf0= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24 h1:xLD2c01e4ZJD9QoUINYfN2QRlBsKuxduzKtpk8oVjo0= +github.com/margnus1/go-deepcopy v0.0.0-20140624231552-e90e9caf2f24/go.mod h1:htqcqoNQp32xb0kCqp6zLqMIqg66TiAtr52L2ydpER4= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= +github.com/remogatto/prettytest v0.0.0-20200211072524-6d385e11dcb8 h1:nRDwTcxV9B3elxMt+1xINX0bwaPdpouqp5fbynexY8U= +github.com/remogatto/prettytest v0.0.0-20200211072524-6d385e11dcb8/go.mod h1:jOEnp79oIHy5cvQSHeLcgVJk1GHOOHJHQWps/d1N5Yo= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/5-appendix/03_with-third-party-import/init b/5-appendix/03_with-third-party-import/init deleted file mode 100644 index 2f6a36c..0000000 --- a/5-appendix/03_with-third-party-import/init +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -# Author : Lex Sheehan -# Purpose: This script initializes a go project with glide dependency management -# For details see: https://www.amazon.com/Learning-Functional-Programming-Lex-Sheehan-ebook/dp/B0725B8MYW -# License: MIT, 2017 Lex Sheehan LLC -MY_DEV_DIR=~/dev -CURRENT_GO_VERSION=1.9.2 -USES_TOML_CONFIG_YN=no -LOCAL_BIN_DIR=/usr/local/bin/ -#WIN_GOPATH="E:\\\alice\\\dev\\\learn-fp-go\\\1-functional-fundamentals\\\ch01-pure-fp\\\01_oop" -# --------------------------------------------------------------- -# Verify variables above are correct. Do not modify lines below. -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - export GOBIN="$GOPATH\\bin" - pushd $HOME - popd -fi -if [ -L "$(pwd)" ]; then - echo "You must be in the real project directory to run this init script. You are currently in a linked directory" - echo "Running: ln -l \"$(pwd)\"" - ls -l "$(pwd)" - return -fi -CURRENT_GOVERSION="go$CURRENT_GO_VERSION" -ORIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$MY_DEV_DIR/$(basename $ORIG_DIR)" -PROJECT_DIR_LINK="$MY_DEV_DIR/$(basename $ORIG_DIR)" -if [ -L "$PROJECT_DIR_LINK" ]; then - rm "$PROJECT_DIR_LINK" -fi -if [ ! -d "$MY_DEV_DIR" ]; then - mkdir "$MY_DEV_DIR" -fi -# Create link to project directory in MY_DEV_DIR -set -x -ln -s "$ORIG_DIR" "$PROJECT_DIR_LINK" -{ set +x; } 2>/dev/null -cd "$PROJECT_DIR_LINK" -if [ -z $WIN_GOPATH ]; then - export GOPATH=$ORIG_DIR - export GOBIN=$ORIG_DIR/bin -fi -if [ -e "$GOBIN" ]; then - rm "$GOBIN/*" 2>/dev/null -else - mkdir "$GOBIN" -fi -#[ $(which "$(basename $(pwd))") ] && { echo "An executable named $(basename $(pwd)) found on path here: $(which $(basename $(pwd))). Continue anyway? (yes/no)"; read CONTINUE_YN; if [[ "$CONTINUE_YN" =~ ^(yes|y)$ ]]; then echo 'Okay, but when you run go-run it may run the pre-existing binary.'; else echo "You might want to rename this project directory ($(basename $(pwd))) to a name that does not match a pre-existing binary name."; return; fi; } 2>/dev/null -APP_NAME=$(basename $(pwd)) -GOVERSION=$(go version) -echo "Installed Go version: $GOVERSION" -type goenv 2>/dev/null -if [ $? == 0 ]; then - # Attempt to automatically set desired/current go version. This requires goenv. - . goenv "$CURRENT_GO_VERSION" - echo "GOVERSION: $GOVERSION" - echo "CURRENT_GOVERSION: $CURRENT_GOVERSION" - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed" - return - fi -else - if [ -z "$GOVERSION" ] || [[ "$(echo $GOVERSION | awk '{print $3}')" != "$CURRENT_GOVERSION" ]]; then - echo "Expected Go version $CURRENT_GOVERSION to be installed. Consider using github.com/l3x/goenv to manage your go runtimes." - return - fi -fi -command -v goimports >/dev/null 2>&1 || { echo >&2 "Missing goimports. For details, see: https://github.com/bradfitz/goimports"; return; } -command -v glide >/dev/null 2>&1 || { echo >&2 "Missing glide. For details, see: https://github.com/Masterminds/glide"; return; } -if [ ! -e ./src ]; then - mkdir src -fi - -if [ ! -e ./src/mypackage/ ]; then - mkdir ./src/mypackage -fi - -if [ ! -e ./src/mypackage/myname.go ]; then - cat > ./src/mypackage/myname.go < ./main.go < ./.gitignore < config.toml - fi - ls -l config.toml - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe -config ./config.toml" - else - alias go-run="go install && $APP_NAME -config ./config.toml" - fi -else - if [ ! -z $WIN_GOPATH ]; then - alias go-run="go build && ./$APP_NAME.exe" - else - alias go-run="go install && $APP_NAME" - fi -fi -alias go-test='go test ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias go-test-bench='go test -bench=. ./... 2>&1 | grep -v "$(basename $(pwd))\t\[no test files"' -alias glide-ignore-project-dirs="printf \"ignore:\n$(find ./src -maxdepth 1 -type d | tail -n +2 | sed 's|./src\/||' | sed -e 's/^/- \.\//')\n\"" -alias prune-project="(rm -rf bin pkg vendors;rm glide.*;rm -rf ./src/mypackage;sed -i -e '/mypackage/ s/^#*/\/\//' main.go) 2>/dev/null" -alias show-path='echo $PATH | tr ":" "\n"' -alias prune-path='export PATH="$(echo $PATH | tr ":" "\n" | uniq | grep -v "$(dirname $ORIG_DIR)" | tr "\n" ":")"; if [[ "$PATH" =~ ':'$ ]]; then export PATH="${PATH::-1}";fi' -alias find-imports='find . -type f -name "*.go" -exec grep -A3 "import" {} \; -exec echo {} \; -exec echo --- \;' -alias go-fmt='set -x;goimports -w main.go src/*;{ set +x; } 2>/dev/null' -if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH="$WIN_GOPATH:$WIN_GOPATH\\\vendors" && export GOBIN="$WIN_GOPATH/bin" && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH="$GOPATH"\\\\vendors:"$GOPATH";echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -else - alias glide-update='if [ ! -z $(readlink `pwd`) ]; then export LINKED=true && pushd "$(readlink `pwd`)"; fi;rm -rf {vendor,vendors};rm glide.* 2>/dev/null;export GOPATH=$(pwd):$(pwd)/vendors && export GOBIN=$(pwd)/bin && glide init --non-interactive && glide-ignore-project-dirs >> glide.yaml && glide up && mvglide && if [ $LINKED==true ]; then popd;fi' - alias mvglide='mkdir -p vendors && mv vendor/ vendors/src/ && export GOPATH=$(pwd)/vendors:$(pwd);echo "vendor packages have been moved to $(pwd)/vendors and your GOPATH: $GOPATH"' -fi -tdml() { - if [ -z $1 ]; then LEVEL=2; else LEVEL=$1;fi - tree -C -d -L $LEVEL -} -get-go-binary() { - GO_BINARY_URL="$1" - if [ -z $GO_BINARY_URL ]; then - echo "Missing GO_BINARY_URL. Usage: get-go-binary Example: get-go-binary github.com/nicksnyder/go-i18n/goi18n" - return - fi - TMP_DIR="tmp_dir_$RANDOM"; mkdir "$TMP_DIR"; pushd "$TMP_DIR"; - if [ ! -z $WIN_GOPATH ]; then - export GOPATH="$WIN_GOPATH" - else - export GOPATH="$(pwd)" - fi - go get -u $GO_BINARY_URL; popd; rm -rf "$TMP_DIR" -} -echo You should only need to run this init script once. -echo Add Go source code files under the src directory. -echo After updating dependencies, i.e., adding a new import statement, run: glide-update -echo To build and run your app, run: go-run diff --git a/5-appendix/03_with-third-party-import/init-windows.sh b/5-appendix/03_with-third-party-import/init-windows.sh deleted file mode 100755 index f226208..0000000 --- a/5-appendix/03_with-third-party-import/init-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Installing goimports..." -export GOPATH=C:\\Go\\src\\ -mkdir -p $GOPATH\\golang.org\\x\\tools -cd $GOPATH\\golang.org\\x\\tools -git clone https://go.googlesource.com/tools . -cd $GOPATH -cd golang.org/x/tools/cmd/goimports -go build -cp ./goimports.exe /usr/local/bin - -echo "Installing glide..." -cd $GOPATH -mkdir -p github.com/Masterminds/glide -cd github.com/Masterminds/glide -git clone https://github.com/Masterminds/glide.git . -go build -cp ./glide.exe /usr/local/bin/ - -echo "Installed goimports and $(glide --version)" diff --git a/5-appendix/03_with-third-party-import/main.go b/5-appendix/03_with-third-party-import/main.go index fc4e995..4f6a152 100644 --- a/5-appendix/03_with-third-party-import/main.go +++ b/5-appendix/03_with-third-party-import/main.go @@ -1,10 +1,9 @@ package main import ( - a "packagea" + a "03_with-third-party-import/packagea" ) func main() { a.Atask() } - diff --git a/5-appendix/03_with-third-party-import/src/packagea/featurea.go b/5-appendix/03_with-third-party-import/packagea/featurea.go similarity index 76% rename from 5-appendix/03_with-third-party-import/src/packagea/featurea.go rename to 5-appendix/03_with-third-party-import/packagea/featurea.go index 712fd4c..43a82ad 100644 --- a/5-appendix/03_with-third-party-import/src/packagea/featurea.go +++ b/5-appendix/03_with-third-party-import/packagea/featurea.go @@ -1,8 +1,9 @@ package packagea import ( - b "packageb" + b "03_with-third-party-import/packageb" "fmt" + u "github.com/go-goodies/go_utils" ) @@ -10,4 +11,3 @@ func Atask() { fmt.Println(u.PadLeft("A", 3)) b.Btask() } - diff --git a/5-appendix/03_with-third-party-import/src/packageb/featureb.go b/5-appendix/03_with-third-party-import/packageb/featureb.go similarity index 100% rename from 5-appendix/03_with-third-party-import/src/packageb/featureb.go rename to 5-appendix/03_with-third-party-import/packageb/featureb.go diff --git a/Dockerfile b/Dockerfile index a48f3fa..1e0ad4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,32 @@ -FROM golang:1.15 -MAINTAINER Michele Bertasi -MAINTAINER Aleksey Kislitsa +FROM golang:1.18 +LABEL MAINTAINER Michele Bertasi +LABEL MAINTAINER Aleksey Kislitsa ADD fs/ / ADD go-env /usr/local/bin +ADD go-init /usr/local/bin ADD go-ide /usr/local/bin # install pagkages RUN apt-get update && \ - apt-get install -y ncurses-dev libtolua-dev exuberant-ctags gdb && \ + apt-get install -y ncurses-dev libtolua-dev \ + exuberant-ctags gdb vim-nox && \ ln -s /usr/include/lua5.2/ /usr/include/lua && \ ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/lib/liblua.so && \ # cleanup apt-get clean && rm -rf /var/lib/apt/lists/* -# build and install vim -RUN cd /tmp && \ - git clone --depth 1 https://github.com/vim/vim.git && \ - cd vim && \ - ./configure --with-features=huge --enable-luainterp \ - --enable-gui=no --without-x --prefix=/usr && \ - make VIMRUNTIMEDIR=/usr/share/vim/vim82 && \ - make install && \ -# cleanup - rm -rf /tmp/* /var/tmp/* - # get go tools -RUN go get golang.org/x/tools/cmd/godoc && \ - go get github.com/nsf/gocode && \ - go get golang.org/x/tools/cmd/goimports && \ - go get github.com/rogpeppe/godef && \ - go get golang.org/x/tools/cmd/gorename && \ - go get golang.org/x/lint/golint && \ - go get github.com/kisielk/errcheck && \ - go get github.com/jstemmer/gotags && \ - go get github.com/tools/godep && \ - GO111MODULE=on go get golang.org/x/tools/gopls@latest && \ +RUN go install golang.org/x/tools/cmd/godoc@latest && \ + go install github.com/nsf/gocode@latest && \ + go install golang.org/x/tools/cmd/goimports@latest && \ + go install github.com/rogpeppe/godef@latest && \ + go install golang.org/x/tools/cmd/gorename@latest && \ + go install golang.org/x/lint/golint@latest && \ + go install github.com/kisielk/errcheck@latest && \ + go install github.com/jstemmer/gotags@latest && \ + go install github.com/tools/godep@latest && \ + go install golang.org/x/tools/gopls@latest && \ mv /go/bin/* /usr/local/go/bin && \ # cleanup rm -rf /go/src/* /go/pkg diff --git a/go-init b/go-init new file mode 100755 index 0000000..4da4c0b --- /dev/null +++ b/go-init @@ -0,0 +1,7 @@ +#!/bin/sh + +gomodinit() { + go mod init ${PWD##*/} && go mod tidy +} + +gomodinit