Skip to main content

Http Status Code and Meanings

· One min read
Sarvsav Sharma
Http Status Code and Meanings

2xx Successful

Status CodeMeaning
200OK
201Created
204No Content

3xx Redirection

Status CodeMeaning
301Moved Permanently
302Found
304Not Modified

4xx Client Error

Status CodeMeaning
400Bad Request
401Unauthorized
403Forbidden
404Not Found
405Method Not Allowed
408Request Timeout
409Conflict
410Gone
422Unprocessable Content

5xx Server Error

Status CodeMeaning
500Internal Server Error
502Bad Gateway
503Service Unavailable
504Gateway Timeout

Setting up database process

· 3 min read
Sarvsav Sharma
Go Starter Template Core Team

Let us understand on how to set up the things that will help to connect and perform the crud operations with database.

Requirements

We will use postgres for our development, and below are the list of tools that needs to be installed and setup in the environment PATH. Use the installation script from scripts directory for installation of tools.

Creating migration

First step, is to create a table inside the database to store data. To create a table, use the command migrate-table from make file. For demonstration purpose, let's use the albums example.

$ make migrate-table
Enter the table name: album
goose -dir db/migrations create create_album sql
2024/06/21 20:02:01 Created new file: db/migrations/20240621180201_create_album.sql

It will create a new file inside folder db/migrations with date_create__varname__.sql, with default queries. Next, we need to add a create table syntax that will run when we use goose up and drop table syntax on running goose down.

This is the content of the file.

-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query';
-- +goose StatementEnd
CREATE TABLE albums (
ID uuid PRIMARY KEY,
Title TEXT NOT NULL,
Artist TEXT NOT NULL,
Price NUMERIC(10,2) NOT NULL
);

-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query';
-- +goose StatementEnd
drop table albums;

Writing queries

Next step is to write the sql queries for CRUD operations in sqlc format inside folder named db/queries. These sql queries would be used to generate the go code with help of sqlc. The filename should be same as of the table name. Follow the naming convention for your function names.

  • CreatResource
  • GetResource
  • ListResources
  • UpdateResource
  • DeleteResource

Writing sqlc configuration file

Create a file named in sqlc.yaml in your project root. This file defines the configuration for sqlc. It is used to generate Go code from SQL queries.

## Filename: sqlc.yaml
version: "2"
cloud:
organization: "Go Starter Template"
project: "GoStarterTemplate"
hostname: "go-starter-template.com"
sql:
- engine: "postgresql"
queries: "./db/queries/"
schema: "./db/migrations/"
gen:
go:
package: "db"
out: "./db/sqlc"
overrides:
go: null
plugins: []
rules: []
options: {}

Generating Go code

The go code now can simply be generated using the sqlc command.

sqlc generate

It will generate the files inside db/sqlc directory. Please DO NOT EDIT them as they get overwritten by sqlc.

The above process will setup the things to work with database using Go.

Welcome

· One min read
Sébastien Lorber
Docusaurus maintainer
Yangshun Tay
Front End Engineer @ Facebook

Docusaurus blogging features are powered by the blog plugin.

Simply add Markdown files (or folders) to the blog directory.

Regular blog authors can be added to authors.yml.

The blog post date can be extracted from filenames, such as:

  • 2019-05-30-welcome.md
  • 2019-05-30-welcome/index.md

A blog post folder can be convenient to co-locate blog post images:

Docusaurus Plushie

The blog supports tags as well!

And if you don't want a blog: just delete this directory, and use blog: false in your Docusaurus config.

First Blog Post

· One min read
Gao Wei
Docusaurus Core Team

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet