Categorygithub.com/AliiAhmadi/ShareCode
module
0.0.0-20240226034919-bb74d98894ea
Repository: https://github.com/aliiahmadi/sharecode.git
Documentation: pkg.go.dev

# README

ShareCode

Screenshot_20231209_054535

Setup

# Clone source code
$ git clone https://github.com/AliiAhmadi/ShareCode.git

# Create mysql database and table and also a user for database connection(Go to `Database` section)

#
$ cd ShareCode/

# Make a directory for self signed ssl certification and private key
$ mkdir tls

#
$ cd tls/

# Make ssl certification and private key
$ go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost

# Back to the root of project
$ cd ..

#
$ shopt -s extglob

# Run unit tests
$ go test ./...

# Run application
$ go run ./cmd/web/!(*_test).go

Routes

MethodPatternAction
GET/Home page
GET/snippet/:idGet a specific snippet
GET/snippet/createGet new snippet form
GET/snippet/createCreate new snippet
POST/static/Serve static files
GET/user/signupDisplay signup form
POST/user/signupCreate new user
GET/user/loginDisplay login form
POST/user/loginLogin the user
POST/user/logoutLogout the user

Database

-- Create a new database.
CREATE DATABASE sharecode;

-- Switvh to using 'sharecode' database.
USE sharecode;

-- Create 'snippets' table.
CREATE TABLE snippets (
  id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(100) NOT NULL,
  content TEXT NOT NULL,
  created DATETIME NOT NULL,
  expires DATETIME NOT NULL
);

-- Add an index on 'created' column.
CREATE INDEX idx_snippets_created ON snippets(created);

-- Add some dummy records.
INSERT INTO snippets (title, content, created, expires) VALUES (
  'An old silent pond',
  'An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again.',
  UTC_TIMESTAMP(),
  DATE_ADD(UTC_TIMESTAMP(), INTERVAL 365 DAY)
);

INSERT INTO snippets (title, content, created, expires) VALUES (
  'Over the wintry forest',
  'Over the wintry\nforest, winds howl in rage\nwith no leaves to blow.',
  UTC_TIMESTAMP(),
  DATE_ADD(UTC_TIMESTAMP(), INTERVAL 365 DAY)
);

INSERT INTO snippets (title, content, created, expires) VALUES (
  'First autumn morning',
  'First autumn morning\nthe mirror I stare into\nshows my father''s face.',
  UTC_TIMESTAMP(),
  DATE_ADD(UTC_TIMESTAMP(), INTERVAL 7 DAY)
);

CREATE TABLE users (
  id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  hashed_password CHAR(60) NOT NULL,
  created DATETIME NOT NULL
);

ALTER TABLE users ADD CONSTRAINT users_uc_email UNIQUE (email);

Database user

CREATE USER 'sharecode'@'localhost';
GRANT SELECT, INSERT ON sharecode.* TO 'sharecode'@'localhost';

-- Replace 'pass' with your password.
ALTER USER 'sharecode'@'localhost' IDENTIFIED BY 'pass';

Author

Ali Ahmadi

# Packages

No description provided by the author
No description provided by the author
No description provided by the author