GithubHelp home page GithubHelp logo

krtffl / go-mixtape-trading Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 35 KB

create a playlist that expresses how you feel or think about your friends. add songs that remind you of them, reflect your shared memories, or simply represent your friendship.

License: MIT License

Go 98.32% Dockerfile 1.68%

go-mixtape-trading's Introduction

Go Mixtape Trading

Go Mixtape Trading is a web application that allows users to trade mixtapes with each other.

Installation

To install and run the application, you will need to have Go 1.16 or later installed on your system.

  1. Clone the repository: git clone https://github.com/perezdid/go-mixtape-trading.git
  2. Change into the project directory: cd go-mixtape-trading
  3. Copy the .env.example file to .env and set the appropriate values for your environment.
  4. Build and run the server: go run cmd/server/main.go

Usage

Once the server is running, you can use a web browser or a command-line tool like curl to interact with the API. The following endpoints are available:

  • GET /status: Returns the status of the server.
  • POST /login: Authenticates a user and returns an access token.
  • GET /user/{id}: Returns information about a user.
  • GET /playlist/{id}: Returns information about a playlist.
  • POST /playlist: Creates a new playlist.
  • PUT /playlist/{id}: Updates an existing playlist.
  • DELETE /playlist/{id}: Deletes a playlist.

For more information about each endpoint, refer to the documentation in the internal/api/handlers directory.

Folder Structure

The project follows a standard Go project layout. Here is an overview of the folder structure:

  • cmd/server: The main entry point for the server.
  • internal/api/handlers: The API endpoints and request handlers.
  • internal/api/models: The data models and database access functions.
  • config: Configuration settings for the application.
  • middleware: Reusable middleware functions.
  • utils: Utility functions.

TLS Configuration

This project uses HTTPS to secure communication between clients and the server. To set up HTTPS, you need to generate a TLS certificate and key file.

Generating a Self-Signed Certificate and Key

For testing purposes, you can generate a self-signed certificate and key using the openssl command-line tool. To generate a new certificate and key, run the following command in a terminal:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

This command will create a new RSA private key and a self-signed X.509 certificate that is valid for 365 days.

Configuring the Server

Once you have generated the TLS certificate and key files, you need to configure the server to use them. In the main.go file, update the tlsConfig variable to load the certificate and key files:

// Load TLS certificate and key
certFile := "cert.pem"
keyFile := "key.pem"
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
    log.Fatalf("error loading TLS certificate and key: %v", err)
}

tlsConfig := &tls.Config{
    Certificates: []tls.Certificate{cert},
}

Make sure to replace cert.pem and key.pem with the paths to your own certificate and key files.

Production Considerations

For production use, you should obtain a trusted TLS certificate from a certificate authority (CA) instead of using a self-signed certificate. A trusted TLS certificate ensures that client browsers and other software will trust your server's identity, reducing the risk of man-in-the-middle attacks and other security vulnerabilities.

You can obtain a trusted TLS certificate from a CA

go-mixtape-trading's People

Contributors

krtffl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.