#golang programming
Explore tagged Tumblr posts
Text



Definitely this counts as productive night of studies.
I arrived early, grabbed my seat, and dive into another incredible Golang SP event at Microsoft Reactor.
During the event, we discussed the simplicity of error handling in Go, which was practically reinforced by creating a CSV file parser, ensuring that any issues encountered are well identified and handled.
#coding#developer#linux#programmer#programming#software#software development#student#study aesthetic#study blog#studyblr#studyblr community#studyprogramming#swe#software engineering#softwareengineer#code#golang#notebook#laptop#event#codeevent#programmingevent#study motivation#studying#studynotes#brazil#brasil
35 notes
·
View notes
Text
One thing I like about Go (the programming language) is that it has a really funny little mascot, which I think more programming languages should have. So here is the Go Gopher Playing Go, which is now a sticker you can get!
9 notes
·
View notes
Photo
Commission - Golang!
A cute lil commission finished for Sveken of his dragon sporting golang merch. So cute <3
Posted using PostyBirb
#dragons#dragon#fantasy#fiction#cute#chibi#flat#digital art#art#my art#istaria#istaria: chronicles of the gifted#horizons: empire of istaria#golang#go#programming
8 notes
·
View notes
Text
Simple boid simulation
Hello! over the past weekend I made a very quick flocking simulation in ebitengen. Each little boid follows a few simple rules - defined here: https://en.wikipedia.org/wiki/Boids plus an extra rule of my own to flee from the mouse cursor. Longer blog/discussion under the cut
I'm still trying to dip my toes into the gamedev world (most of my experience is in web technologies) and this was a fun little afternoon project to get to know things a bit better. I chose ebitengine for a couple reasons: first, I feel a little more comfortable with the code-only or code-first engines/frameworks coming from a non-gamedev coding background, and second, I've really been liking Go/Golang from what I've tried so far. A fun, but perhaps overboard, fact about this little demo is each boid calculates its next move in a go function, so the 'game' is multi-threaded. Also on my list of frameworks to try is monogame since C# is the language I've worked with the most professionally and it has a good reputation. I still have some hang-ups about tying myself to a Microsoft product, though - every time I look at the naming conventions of different versions of .NET I want to rethink my career choices, for example.
I'm not sure how far I'll take this idea, but I did have a loose plan to expand this little simulation into a prototype for a sheep herding game. However, spending more time thinking about what it would take to bring this into a full game makes me a little hesitant to fully commit to using a tool like ebitengine. Essentially, once I need a level editor I'm a bit worried if it would be a better use of time in the long run to just use a full fledged engine like Godot. Still, other big projects have gotten by on tools without built-in level editors in the past, so maybe its not as big of a downside as I think.
That's it for this first update post! I'm hoping to post little summaries like this of my future hobby projects, as well as maybe some older things I've done. If you've read this far, thanks a ton! If you're curious about how I made this feel free to ask away
13 notes
·
View notes
Text
The Google programming language gopher *hands down* wins the award for best/worst/scrunkliest mascot:


Source: [1] [2] [3] [4]
#absolute specimen#creature#the scrunkly#the skrunkly#scrunkly scrimblo#scrimblo#i love him#codeblr#coding#golang#golang gopher#mascot design#model sheet#programming#not my art#h8yqql
5 notes
·
View notes
Text
Do You Want Some Cookies?
Doing the project-extrovert is being an interesting challenge. Since the scope of this project shrunk down a lot since the first idea, one of the main things I dropped is the use of a database, mostly to reduce any cost I would have with hosting one. So things like authentication needs to be fully client-side and/or client-stored. However, this is an application that doesn't rely on JavaScript, so how I can store in the client without it? Well, do you want some cookies?
Why Cookies
I never actually used cookies in one of my projects before, mostly because all of them used JavaScript (and a JS framework), so I could just store everything using the Web Storage API (mainly localstorage). But now, everything is server-driven, and any JavaScript that I will add to this project, is to enhance the experience, and shouldn't be necessary to use the application. So the only way to store something in the client, using the server, are Cookies.
TL;DR Of How Cookies Work
A cookie, in some sense or another, is just an HTTP Header that is sent every time the browser/client makes a request to the server. The server sends a Set-Cookie header on the first response, containing the value and optional "rules" for the cookie(s), which then the browser stores locally. After the cookie(s) is stored in the browser, on every subsequent request to the server, a Cookie header will be sent together, which then the server can read the values from.
Pretty much all websites use cookies some way or another, they're one of the first implementations of state/storage on the web, and every browser supports them pretty much. Also, fun note, because it was one of the first ways to know what user is accessing the website, it was also heavy abused by companies to track you on any website, the term "third-party cookie" comes from the fact that a cookie, without the proper rules or browser protection, can be [in summary] read from any server that the current websites calls. So things like advertising networks can set cookies on your browser to know and track your profile on the internet, without you even knowing or acknowledging. Nowadays, there are some regulations, primarily in Europe with the General Data Privacy Regulation (GDPR), that's why nowadays you always see the "We use Cookies" pop-up in websites you visit, which I beg you to actually click "Decline" or "More options" and remove any cookie labeled "Non-essential".
Small Challenges and Workarounds
But returning to the topic, using this simple standard wasn't so easy as I thought. The code itself isn't that difficult, and thankfully Go has an incredible standard library for handling HTTP requests and responses. The most difficult part was working around limitations and some security concerns.
Cookie Limitations
The main limitation that I stumbled was trying to have structured data in a cookie. JSON is pretty much the standard for storing and transferring structured data on the web, so that was my first go-to. However, as you may know, cookies can't use any of these characters: ( ) < > @ , ; : \ " / [ ] ? = { }. And well, when a JSON file looks {"like":"this"}, you can think that using JSON is pretty much impossible. Go's http.SetCookie function automatically strips " from the cookie's value, and the other characters can go in the Set-Cookie header, but can cause problems.
On my first try, I just noticed about the stripping of the " character (and not the other characters), so I needed to find a workaround. And after some thinking, I started to try implementing my own data structure format, I'm learning Go, and this could be an opportunity to also understand how Go's JSON parsing and how mostly struct tags works and try to implement something similar.
My idea was to make something similar to JSON in one way or another, and I ended up with:
Which, for reference, in JSON would be:
This format is something very easy to implement, just using strings.Split does most of the job of extracting the values and strings.Join to "encode" the values back. Yes, this isn't a "production ready" format or anything like that, but it is hacky and just a small fix for small amounts of structured data.
Go's Struct Tags
Go has an interesting and, to be honest, very clever feature called Struct Tags, which are a simple way to add metadata to Structs. They are simple strings that are added to each field and can contain key-value data:
Said metadata can be used by things such the encoding/json package to transform said struct into a JSON object with the correct field names:
Without said tags, the output JSON would be:
This works both for encoding and decoding the data, so the package can correctly map the JSON field "access_token" to the struct field "Token".
And well, these tokens aren't limited or some sort of special syntax, any key-value pair can be added and accessed by the reflect package, something like this:
Learning this feature and the reflect package itself, empowered me to do a very simple encoding and decoding of the format where:
Can be transformed into:
And that's what I did, and the [basic] implementation source code just has 150 lines of code, not counting the test file to be sure it worked. It works, and now I can store structured data in cookies.
Legacy in Less Than 3 Weeks
And today, I found that I can just use url.PathEscape, and it escapes all ( ) < > @ , ; : \ " / [ ] ? = { } characters, so it can be used both in URLs and, surprise, cookie values. Not only that, but something like base64.URLEncoding would also work just fine. You live, and you learn y'know, that's what I love about engineering.
Security Concerns and Refactoring Everything
Another thing that was a limitation and mostly worry about me, is storing access tokens on cookies. A cookie by default isn't that secure, and can be easily accessed by JavaScript and browser extensions, there are ways to block and secure cookies, but even then, you can just open the developer tools of the browser and see them easily. Even though the only way to something malicious end up happening with these tokens are if the actual client end up being compromised, which means the user has bigger problems than just a social media token being leaked, it's better to try preventing these issues nonetheless (and learn something new as always).
The encryption and decryption part isn't so difficult, Go already provides packages for encryption under the crypto module. So I just implemented an encryption that cyphers a string based on a key environment variable, which I will change every month or so to improve security even more.
Doing this encryption on every endpoint would be repetitive, so adding a middleware would be a solution. I already made a small abstraction over the default Go's router (the DefaultMuxServer struct), which I'm going to be honest, wasn't the best abstraction, since it deviated a lot from Go's default HTTP package conventions. This deviation also would difficult the implementation of a generic middleware that I could use in any route or even any function that handles HTTP requests, a refactor was needed. Refactoring made me end up rewriting a lot of code and simplifying a lot of the code from the project. All routes now are structs that implement the http.Handler interface, so I can use them outside the application router and test them if needed; The router ends up being just a helper for having all routes in a struct, instead of multiple mux.HandleFunc calls in a function, and also handles adding middlewares to all routes; Middlewares end up being just a struct that can return a wrapped HandlerFunc function, which the router calls using a custom/wrapped implementation of the http.ResponseWriter interface, so middlewares can actually modify the content and headers of the response. The refactor had 1148 lines added, and 524 removed, and simplified a lot of the code.
For the encryption middleware, it encrypts all cookie values that are set in the Set-Cookie header, and decrypts any incoming cookie. Also, the encrypted result is encoded to base64, so it can safely be set in the Set-Cookie header after being cyphered.
---
And that's what I worked in around these last three days, today being the one where I actually used all this functionality and actually implemented the OAuth2 process, using an interface and a default implementation that I can easily reimplement for some special cases like Mastodon's OAuth process (since the token and OAuth application needs to be created on each instance separately). It's being interesting learning Go and trying to be more effective and implement things the way the language wants. Everything is being very simple nonetheless, just needing to align my mind with the language mostly.
It has been a while since I wrote one of these long posts, and I remembered why, it takes hours to do, but it's worth the work I would say. Unfortunately I can't write these every day, but hopefully they will become more common, so I can log better the process of working on the projects. Also, for the 2 persons that read this blog, give me some feedback! I really would like to know if there's anything I could improve in the writing, anything that ended up being confusing, or even how I could write the image description for the code snippets, I'm not sure how to make them more accessible for screen reader users.
Nevertheless, completing this project will also help to make these post, since the conversion for Markdown to Tumblr's NPF in the web editor sucks ass, and I know I can do it better.
2 notes
·
View notes
Text
Figuring out how to get the average color of an image...
I could just loop through the image and average out the RGB values like this:
But it'll iterate through every single pixel. It will struggle with 500x200 images (100,000 pixels). Another solution is to select 50 random pixels from the image and get the average of that, but I don't know how accurate that will be.
So, stuck with a problem I am incapable of solving by myself... I searched for a path that other people that have traversed before.
Turns out, if you get the average color of an image, it turns into the color of vomit.
From that information, my goal changed from getting the average to getting the most dominant color.
I could do this using a histogram to count every color, but it only works when there are a few colors (less than 50) to avoid inaccurate results.
What I could do is somehow flatten the entire image into base colors. A palette of some sorts.
...
PalettedImage.
I do have the palette!
All I need to do is count the pixels that are similar to it and see what the dominant color is.
But how can I define "similar colors"?
Update soon-ish.
(This problem might be related to nearest-neighbor search)
6 notes
·
View notes
Text
do you think that ferris the crab and the Go Gopher kiss when no one’s looking
6 notes
·
View notes
Text
Unlike 99% of human languages, computer languages are designed. Many of them never catch on for real applications. So what makes a computer language successful? Here's one case study...
#software development#software engineering#golang#coding#artificial language#concurrency#google#programming languages#compiler#computing history#mascot#gophers
5 notes
·
View notes
Text
Making a compiler
Every programmer out there, new or experienced longs for a chance to create their own programming language and compiler. I am no exception. Months ago I decided to fork an old project on github and develop it in my image. The project was a golang-like unfinished compiler, so I dug in and made changes. I changed the language to resemble a subset of rust, go and ocaml. I plan to add a LLVM backend inspired by the tre golang compiler. I will continue working on it until it kinda works. I still have a lot to do. check out the project on the link below. If you want to contribute submit a pull request.
#golang#programming#rustlang#compiler#programming languages#c++#typescript#java#javascript#javaris x#java development company#javatpoint#software#developer#sql#open source#python
11 notes
·
View notes
Text
Google Interview Question Revealed!
Checkout our latest video where we have explained the popular Google, Microsoft, Facebook, Amazon interview question "Two Sum" in a simple, step by step and easy to understand way. Watch it now on YouTube : https://youtu.be/JMCTsP0Jxmc
#golang#go#python#coding#programming#tech#leetcodesolution#microsoft#google#amazon#facebook#code#interviewquestion#interviewquestions#interview preparation#java#javascript#c#cpp
2 notes
·
View notes
Text
How to Add in the Go Programming Language.
Como Sumar En El Lenguaje de Programación Go.
👉 https://blog.nubecolectiva.com/como-sumar-en-el-lenguaje-de-programacion-go/
0 notes
Text
Go in Action is a practical guide designed to help developers learn and master the Go programming language. Written by experienced Go developers, the book provides a hands-on approach to understanding Go's unique features, concurrency model, and ecosystem. Below is a step-by-step breakdown of the key outcomes and takeaways from the book:
#Go#GoLang#GoInAction#GoProgramming#SoftwareDevelopment#GoTutorial#GoLangDevelopment#Programming#GoLangProjects#TechBooks#GoLanguage#GoTips#GoCommunity#GoLearning#ProgrammingLanguages#BackendDevelopment#TechEducation#GoDevelopment#GoBestPractices#GoResources#GoCode#GoAppDevelopment#GoTech#GoProgrammingLanguage#GoTipsAndTricks#TechTutorial
0 notes
Text
Took a break from crafting the Lox interpreter and spent the day building a license generator in Go, where I got to try out Cobra (Go library for building CLI apps).
0 notes
Text
Go言語のreflect.Elem()を徹底解説 – ポインタが指す要素の型を取得する方法
本記事では、reflect.Elem()の使い方や実際のコード例を交えながら、Go言語のリフレクションを理解するためのガイドを提供します。
0 notes