Overview
This guide will walk you through setting up the PrivyCode backend server, a Go-based API that enables secure, read-only sharing of private GitHub repositories through expiring viewer links.Prerequisites
Before you begin, ensure you have the following installed:Installation
Install Dependencies
Install all Go dependencies using Go modules:
This will download all required packages including GORM, godotenv, and PostgreSQL drivers as specified in
go.mod.Create GitHub OAuth App
To enable GitHub authentication, you need to create a GitHub OAuth application:
- Go to GitHub Developer Settings
- Click “New OAuth App”
- Fill in the application details:
- Application name: PrivyCode (or your preferred name)
- Homepage URL:
http://localhost:8080 - Authorization callback URL:
http://localhost:8080/github/callback
- Click “Register application”
- Note down your Client ID and generate a Client Secret
Setup PostgreSQL Database
Create a new PostgreSQL database for PrivyCode:Your database URL will look like:
Configure Environment Variables
Create a
.env file in the project root with the following configuration:.env
Environment Variables Reference
Environment Variables Reference
| Variable | Description | Example |
|---|---|---|
PORT | Server port number | 8080 |
DATABASE_URL | PostgreSQL connection string | postgresql://user:pass@localhost:5432/privycode |
GITHUB_CLIENT_ID | OAuth app client ID from GitHub | Iv1.a1b2c3d4e5f6g7h8 |
GITHUB_CLIENT_SECRET | OAuth app client secret from GitHub | a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0 |
GITHUB_CALLBACK_URL | OAuth callback URL | http://localhost:8080/github/callback |
GO_ENV | Environment mode | development or production |
FRONTEND_URL | Frontend application URL | http://localhost:5173 |
MOBILE_URL | Mobile application URL | http://localhost:5173 |
Replace the placeholder values with your actual credentials. The
.env file is git-ignored by default.Run Database Migrations
Uncomment the migration line in Then run the server once to execute migrations:You should see:The migration creates two tables:
cmd/server/main.go to create the database schema:cmd/server/main.go
After the first run, you can comment out
config.RunMigrations() again to avoid running migrations on every startup.- users - Stores GitHub authenticated users
- viewer_links - Stores shareable repository links with expiration and view limits
Testing Your Setup
Verify that your server is running correctly:Test GitHub OAuth Flow
Initiate OAuth
Visit the login endpoint in your browser:This will redirect you to GitHub for authorization.
Test Authenticated Endpoints
Once you have a token, test the authenticated endpoints:API Endpoints Overview
Here’s a quick reference of the available endpoints:Authentication Endpoints
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET | /test | Health check endpoint | No |
GET | /github/login | Initiate GitHub OAuth flow | No |
GET | /github/callback | GitHub OAuth callback | No |
GET | /me | Get current user info | Yes |
Viewer Link Management
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET | /dashboard | Get all viewer links | Yes |
POST | /generate-viewer-link | Create new viewer link | Yes |
PUT | /update-link/:id | Update existing link | Yes |
DELETE | /delete-link/:id | Delete viewer link | Yes |
Public Viewer Endpoints
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET | /view/:token | View repository contents | No |
GET | /view-files/:token/file?path= | View specific file | No |
GET | /view-folder/:token?path= | Browse folders | No |
GET | /view-info/:token | Get repository info | No |
All authenticated endpoints require the
Authorization: Bearer <token> header. See Authentication for more details.Project Structure
Understanding the codebase structure:Next Steps
API Reference
Explore the complete API documentation
Authentication
Learn about OAuth and token management
Viewer Links
Understand how viewer links work
Deployment
Deploy to production
Troubleshooting
Database connection failed
Database connection failed
Error:
Error connecting to DBSolutions:- Verify PostgreSQL is running:
pg_isready - Check your
DATABASE_URLformat is correct - Ensure the database exists:
psql -l | grep privycode - Verify credentials have proper permissions
GitHub OAuth not working
GitHub OAuth not working
Error: GitHub redirects fail or show errorsSolutions:
- Verify
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETare correct - Check
GITHUB_CALLBACK_URLmatches your GitHub OAuth app settings - Ensure callback URL is
http://localhost:8080/github/callbackfor local development - Verify your GitHub OAuth app is not suspended
Port already in use
Port already in use
Error:
bind: address already in useSolutions:- Change the
PORTin your.envfile - Kill the process using port 8080:
lsof -ti:8080 | xargs kill -9
Migrations not running
Migrations not running
Error: Tables not created in databaseSolutions:
- Ensure
config.RunMigrations()is uncommented incmd/server/main.go - Check database connection is successful before migrations run
- Verify GORM AutoMigrate logs in console output
- Manually check tables:
psql -d privycode -c "\dt"
Need Help?
GitHub Issues
Report bugs or request features
Developer
Contact the maintainer