Using gcloud-sdk to Work with Storage Buckets in Rust

gcloud-sdk

At the time of this writing, there is no official Google Cloud library for rust. Google started working on google-cloud-rust, but it’s still under development.

The most popular alternative seems to be gcloud-sdk, so that’s what we’ll be using. This SDK uses tonic to build the gRPC clients, so a little familiarity with tonic, might be helpful.

Since we are going to focus on the Storage API, we need to add this dependency to our Cargo.toml file:

1
gcloud-sdk = { version = "0.27", features = ["google-storage-v2" ] }
Read More

Introduction to Tonic for gRPC in Rust

A few years ago I wrote an article explaining Protocol Buffers, gRPC, and showing how to use them with Java. In this article, I’m going to show how to build the same server and client, but this time with Rust.

Project structure

There are going to be 3 parts for our example:

  • Proto files
  • Server
  • Client

We’ll have a root folder and then a folder for each part:

1
2
3
4
/
├── client
├── protos
└── server
Read More

PostGIS - Working With Geospatial Data in PostgreSQL

In this article, we are going to show how to get started with Geospatial data in PostgreSQL. More specifically, we are going to learn how to store spatial information (e.g. Coordinates in a map) and how we can index and perform searches on this data (e.g. Find all coordinates inside a given area).

Installing PostGIS

PostGIS is an extension of standard PostgreSQL that allows us to work with geospatial data. This means, if the extension is not present, we won’t have these capabilities.

To check if our database has PostGIS, we can use this query:

1
SELECT PostGIS_Version();

If PostGIS is not enabled, we will get a message similar to this one:

1
ERROR:  42883: function postgis_version() does not exist

If PostGIS is enabled, we will get something like this:

1
2
3
4
postgres=# SELECT PostGIS_Version();
            postgis_version
---------------------------------------
 3.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

If PostGIS is not installed on our system, we can follow the installation instructions based on our system.

Read More

Adding Configurations to ESP-IDF projects

In this article, we are going to learn how to write software that uses configuration files using ESP-IDF.

Kconfig

Kconfig is the configuration system used by the Linux kernel and by ESP-IDF. It allows management of project settings through a structured and hierarchical menu system.

It allows developers to write configuration files that specify the available configuration options for a piece of software.

Read More

Sharing the Clipboard. Linux, Vim, Tmux and Docker

In this article, we are going to explore how the clipboard works when using different tools inside a terminal and how we can configure these tools so we get and intuitive experience.

Linux

The most basic example of using the clipboard would be using it directly from the operating system.

Most Linux distributions come with a built-in clipboard. This clipboard works as a temporary data storage that can hold a single item. To add an item to the clipboard, we can select it, right click it and select “Copy” or we can use the shortcut Ctrl-C.

There are different tools that can be used to inspect the clipboard. We will use xclip. To install:

1
sudo apt install xclip
Read More

Internationalization (i18n) of Svelte Apps

Internationalization is the process of making a website that is adaptable to different locales (regions or languages). Translation is a large part of it, but there are other aspects, like date formatting, for example.

There is no single standard way to do internationalization. In this article we’ll learn the approach I chose, but there are other ways to achieve a similar result.

URLs

To make an internationalized app SEO friendly, it’s recommended to have locale-prefixed URLs. This means, if we have a dashboard page, the URL for it will be something like: /<lang>/dashboard.

This, of course, leaves the possibility of someone visiting our pages without a prefix, for example: /dashboard. In this scenario, we will use locale detection to redirect users to the correct page for their language.

Read More

Building Web Servers with Axum

In a previous post, we learned about asynchronous programming with Tokio. This time, we are going to use Axum to build a server that uses Tokio as runtime.

Hello world

Creating a simple server with Axum only requires a few lines:

1
2
3
4
5
6
#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, World!" }));
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

If we run this code, we will see a Hello, World! message if we visit http://localhost:3000.

Read More

Firestore Transactions in Rust

I’m working a project that uses Firestore, so I’m using the firestore crate to help me interact with my database.

There are two examples showing the use of transactions in the source code:

There are some parts of those examples that are a little confusing, so I’m writing this article to try and shed some light.

I was not the only one confused by this, and luckily someone brought this up in a Github issue before I had to.

Read More

Error Handling in Rust

Unrecoverable errors

These errors are a sign that the developer made a mistake. An example of this, could be trying to access an index that is out of bounds. For example:

1
2
3
4
5
6
7
8
fn get_number() -> usize {
    return 5;
}

fn main() {
    let numbers = [1, 2];
    println!("{}", numbers[get_number()]);
}
Read More

Sending E-mails From Rust With Brevo

I’m building a little web server with Rust and as part of it, I’m going to need to send some e-mails to my users. I found a few services that offer an e-mail API with a free tier, and decided to go with Brevo.

Authenticating our domain

In order for our e-mails to reach our users’ inboxes, we need to correctly configure our DKIM and DMARC records so they can be used by Brevo.

We can’t authenticate e-mails from free email providers like Gmail. So, before we can authenticate our domain, we need to own a domain. I’m going to use my blog’s domain (ncona.com).

Read More