Go R1 Day 36
progress
- more taskflow work
- learned how to use io.Multiwriter to have both a stdout stream as well as output captured to a
stringbuilder
. - got confused on reading docs, only to realize I was reading docs for a C# solution. ๐
- used Pterm1 to beautiful console output, which was pretty cool to see in action.
Go R1 Day 35
progress
- Worked with Taskflow a bit more.
- Need to identify better error handling pattern on when to resolve vs handle internal to a function, as it feels like I’m doing needless error checking.
- Wrote func to run terraform init, plan, and apply.
- This takes dynamical inputs for vars and backend file.
- Also dynamically switches terraform versions by running tfswitch.
Definitely more verbose code than powershell, but it’s a good way to get used to Go while achieving some useful automation tasks I need to do.
Example of some code for checking terraform path.
|
|
|
|
However, once I call this, I’m see more effort in handling, which feels like I’m double double work at times.
Go R1 Day 34
progress
- figured out how to import
util/logger.go
as a package - after much confusion due to
logger
,log
,*zerolog.Logger
and more variables all deviously similar in name… how to pass around the initialized package logger that I configure. - learned that global scope and package scoped loggers being initialized at run is concerned an anti-pattern
- properly wrapping to avoid the log initialization on import with
type Logger struct { logger: *zerolog.Logger; }
as an example avoids the same behavior as:var Log *zerolog.Logger
- will evaluate better scoping in the future, but for now figured it would be a ๐ #shipit moment to improve as I can later. 1
Go R1 Day 33
progress
- successfully created logging package using zerolog
- learned about scoping with packages
- linked to a private internal repository and how to leverage the module replace operator to temporarily alter path import from url to local override.
- middleware is a newer concept, so I need to learn more on this later so I can understand how to use to inject special log handling for http requests and other actions.
Thoughts for today are that the pressure of jumping into an existing codebase is resulting in me moving faster than I probably should. I’m going to take some time to keep doing the web fundamentals, lambda, and exercisms to ensure I’m setting a better foundation long-term, and not just winging it. ๐
Go R1 Day 32
progress
- created some structured logging improvements with zerolog
- began exploration of middleware concepts for logging
- generated test stubs using gotests
Go R1 Day 31
progress
- Learned a bit about idiomatic patterns wtih error handling.
- Learned about inline block intiailization of variables using
if err := method(); err != nil {...}
approach. - Considered a bit more idiomatic patterns when I noticed excessibe nested if blocks.
|
|
This would probably be more in alignment with Go standards by writing as:
|
|
This reduces the noise and keeps things pretty flat.
links
Go R1 Day 30
progress
- Built some go functions for build tasks work with terraform and setup of projects using taskflow.
Learned one one to pass in arguments using slices. I’m pretty sure you can use some stringbuilder type functionality to get similar behavior, but this worked fine for my use case.
|
|
Go R1 Day 29
progress
- Evaluated Mage as a replacement for bash/pwsh based tasks for automation with Azure Pipelines.
- Was able to get terraform to run with dynamic configuration using the following approach:
Install with
|
|
Then to get mage-select
run:
|
|
Configure some constants, which I’d probably do differently later. For now, this is a good rough start.
|
|
|
|
Once terraform was initialized, it could be planned.
|
|
- Of interest as well was mage-select, providing a new gui option for easier running by others joining a project.
links
Fix Terraform Provider Path in State
Fixing Terraform provider paths in state might be required after upgrading to 0.13-0.14 if your prior state has the following paths.
First, get the terraform providers from state using: terraform providers
The output should look similar to this:
To fix these, try running the commands to fix state. Please adjust to the required providers your state uses, and make sure your tooling has a backup of the state file in case something goes wrong. Terraform Cloud should have this backed up automatically if it’s your backend.
|
|
The resulting changes can be seen when running terraform providers
and seeing the dash is now gone.
Upgrading to Terraform v0.13 - Terraform by HashiCorp
If you have multiple workspaces in the same folder, you’ll have to run fix on their seperate state files.
This is an example of a quick adhoc loop with PowerShell to make this a bit quicker, using tfswitch
cli tool.
|
|
Go R1 Day 28
progress
- Solved [Hamming Distance] on exercism.io
- Simple problem, but reminded me of how to use string split.
|
|
- Reviewed other solutions, and found my first attempt to split the string wasn’t necessary.
Looks like I can just iterate on the string directly.
I skipped this as it failed the first time.
The error is:
invalid operation: x != b[i] (mismatched types rune and byte)
.
This threw me for a loop initially, as I’m familar with .NET char
datatype.
Golang doesn’t have a char data type. It uses byte and rune to represent character values. The byte data type represents ASCII characters and the rune data type represents a more broader set of Unicode characters that are encoded in UTF-8 format. Go Data Types
Explictly casting the data types solved the error. This would be flexibly for UTF8 special characters.
|
|
With this simple test case, it’s it’s subjective if I’d need rune
instead of just the plain ascii byte
, so I finalized my solution with byte(x)
instead.
|
|
links
Incremental and Consistent
Saying that we do knowledge work but have no time for learning is like saying we do farm work but have no time for planting.
— Allen Holub (@allenholub) February 13, 2021
It’s really hard to prioritize when life gets busy, but it’s important that continued improvement is a priority.
Great at Work: How Top Performers Do Less, Work Better, and Achieve More was a really interesting book. The fact that small incremental improvement done daily can make such a difference is pretty interesting.
It’s similar to Agile tenets in how to approach software design. Smaller iterations with rapid feedback is better than large isolated batches work delivered without regular feedback.
If you find yourself saying, “But I don’t have time” or “When I have some time” it might be indicative of a failure to grasp this. When I catch myself saying this I try to reword it and say “Whenever I make time for this” instead.
You’ll always have pressure on you. The further along in your career and life you go, the more pressure is likely to be on you.
You have to “make” time for improvement and learning if it’s a priority.
Nativefier
Ran across this app, and thought was kinda cool. I’ve had some issues with Chrome apps showing up correctly in certain macOS windows managers to switch context quickly.
Using this tool, you can generate a standalone electron app bundle to run a webpage in as it’s own dedicated window.
It’s cross-platform.
For a site like Azure DevOps, you can run:
|
|
If redirects for permissions occur due to external links opening, you might have to open the application bundle and edit the url mapping. GitHub Issue #706
|
|
Ensure your external urls match the redirect paths that you need such as below. I included the standard oauth redirect locations that Google, Azure DevOps, and Microsoft uses. Add your own such as github to this to have those links open inside the app and not in a new window that fails to recieve the postback.
|
|
Go R1 Day 27
progress
- Iterated through AWS SDK v1 S3 buckets to process IAM policy permissions.
- Unmarshaled policy doc into struct using
Json-To-Struct
.
links
Github Pages Now Supports Private Pages
I’m a huge static site fan (lookup jamstack).
What I’ve historically had a problem with was hosting. For public pages, it’s great.
For private internal docs, it’s been problematic. It’s more servers and access control to manage if you want something for a specific group inside a company to access.
This new update is a big deal for those that want to provide an internal hugo, jekyll, mkdocs, or other static generate based documentation site for their team.
Ensuring Profile Environment Variables Available to Intellij
Open IntelliJ via terminal: open "/Users/$(whoami)/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app"
This will ensure your .profile
, .bashrc
, and other profile settings that might be loading some default environment variables are available to your IDE.
For macOS, you’d have to set in the environment.plist
otherwise to ensure they are available to a normal application.
ref: OSX shell environment variables โ IDEs Support (IntelliJ Platform) | JetBrains
Leverage Renovate for Easy Dependency Updates
Renovate is a great tool to know about. For Go, you can keep modules updated automatically, but still leverage a pull request review process to allow automated checks to run before allowing the update.
This is particularly useful with Terraform dependencies, which I consider notoriously difficult to keep updated. Instead of needing to use ranges for modules, you can start specifying exact versions and this GitHub app will automatically check for updates periodically and submit version bumps.
Why? You can have a Terraform plan previewed and checked for any errors on a new version update with no work. This means your blast radius on updates would be reduced as you are staying up to date and previewing each update as it’s available.
No more 5 months of updates and figuring out what went wrong ๐
Here’s an example json config that shows how to allow automerging, while respecting minor/major version updates not enabling automerge.
Note that you’d want to install the auto-approver app they document in the marketplace if you have pull request reviews required.
In addition, if you use CODEOWNERS
file, this will still block automerge.
Consider removing that if you aren’t really leveraging it.
Go R1 Day 26
Progress
- Evaluated gorm usage best practices with Slack Gopher community.
- Obtained a great example to get me started on go routine and channels usage with multi-database queries.
Remove Chrome Autocomplete Suggestion
Do you have a Chrome suggestion for a domain, url, or specific site location that you don’t want anymore?
You can remove an invalid suggestion that you don’t want popping up each time by using shift+delete
.
If it’s the first entry it will remove it, or use arrow keys to highlight a different entry and press the same command.
Also relevant: To Delete Chrome Address Bar Suggestions with Mouse
Go R1 Day 25
Day 25 of 100
progress
- Worked with Gorm, my first experience with ORM based querying.
- Used
gofakeit
with gorm to connect to MSSQL Server in Docker and randomize name entries. - Learned a bit about
Context
package and how it helps with propagation of cancellation. - As a new user to this, the examples were very confusing as it mixed up go-mssqldb along with examples using just gorm. As I get better with it, I’ll try to log better introductory examples.
links
Go R1 Day 24
Day 24 of 100
progress
- Used glamour to render some nice console output.
- Formatted text testing some text tooling.
- Progressbar ui tested.
- Connected successfully to MSSQL Docker instance and returned results of query, rendering to to console .