We provide a number of examples in bash that use gobash, as well as
an intro tour into shell scripting if you have no prior experience.
Each of the following examples uses some features/functions from
gobash. The examples are sorted such that each might build on an
earlier example. Checking them in order is the recommended, but
depending on your interest that might not be the case.
hello_world_ex- Iterates over some key points related to the librarystructs_ex- Introduces structs and constructorsanonymous_struct_ex- Introduces anonymous structsmethods_ex- Introduces methodserror_ex- Introducesctxused to write and print error messagesresult_ex- IntroducesResultstruct that can be used to return a value from a function / methodto_string_ex- Illustrates the defaultto_stringmethod and overridingto_json_ex- Illustrates the defaultto_jsonmethod and overridinglist_ex- IntroducesListdata structuresmap_ex- IntroducesMapdata structureshapes_ex- Combines structs, methods, and data structureslinked_list_ex- Revisits structs and methods with a random exampleregexp_ex- Illustrates use of the regular expression APIflags_ex- Illustrates parsing of command line flagsflags_details_ex- Illustrates command line parsing with a more concrete examplestrings_ex- Illustrates thestringAPIfile_ex- Illustrates thefileAPImutex_counter_ex- Shows a way to use theMutexstruct for synchronizationwait_group_ex- Shows a way to useWaitGroupstruct to wait for sub processeschan_ex- Introduces theChanstruct for process communicationbinary_trees_ex- Demos tree walk using theChanstructweb_server_ex- Illustrates a simple web server implementationlog_ex- Illustrates log APItext_menu_ex- Demos text-based menutext_spinner_ex- Demos text-based spinnertext_progress_ex- Demos text-based progress barwhiptail_ex- Demos the approach to usewhiptailwindows/UIuser_ex- Illustrates API for accessing user infovisitor_ex- Demos the accept / visit patterntemplate_ex- Demos recommended (but not required) workflow
Below is the list of examples matching those available in the Go
playground. Note that not each example uses/needs gobash.
hellow_world_exclear_screen_exhttp_server_exsleep_extest_function_exconcurrent_pi_exring_do_exring_len_exring_link_exring_move_exring_next_exring_prev_exring_unlink_exlist_ex
We wrote a couple of existing scripts using bash with the gobash
library. Some are included below.
A tour of shell scripting. These examples do not necessarily use
gobash. A few examples are inspired by the sequence in the Go
playground (in which case we provide the link to the original example
inside the file).