Discover Packages
github.com/planetscale/golang-example
command
module
Version:
v0.0.0-...-681f593
Opens a new window with list of versions in this module.
Published: Jan 13, 2023
License: CC0-1.0
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Learn how to integrate PlanetScale with a sample Go application
This sample application demonstrates how to connect to a PlanetScale MySQL database, create and run migrations, seed the database, and display the data.
For the full tutorial, see the Go PlanetScale documentation .
Set up the Go app
Clone the starter Go application:
git clone https://github.com/planetscale/golang-example
Navigate into the folder:
cd golang-example
Copy the .env.example
file into .env
:
cp .env.example .env
Set up the database
Sign up for a free PlanetScale account .
Create a new database. A default branch, main
, will be created for you.
Connect to the Go app
On the database overview page in the PlanetScale dashboard, click "Connect ".
Click "New password ".
In the "Connect to " dropdown, select Go.
Copy the connection string.
Open your .env
file and paste the connection string in as the value for DSN
. You're now connected!
Run migrations and seeder
Start the Go app:
go run .
Navigate to localhost:8080/seed
to run the migrations and the seeder.
View the product and category data as follows:
Expand ▾
Collapse ▴
Documentation
¶
Command golang-example demonstrates how to connect to PlanetScale from a Go
application.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.