Go Notebook
  • Introduction
  • Syntax Helpers
    • Append
    • String
    • Slice
  • Idioms
    • Custom JSON Marshaling
    • Functional Options
    • Type Embedding
    • Laws of Reflection
  • Design Patterns
    • Builder
    • Factory Method
    • Object Pool
    • Singleton
    • Observer
    • Strategy
  • Hello World
    • Getting Started With Go
    • Go Packages
    • Hello World
  • Tic Tac Toe
    • Go Interfaces
    • Go Error Handling
    • Tic Tac Toe
  • HTTP Server
    • HTTP Handler
    • Build a Calculator
    • HTTP Unit Test
  • Concurrency
    • Goroutines
    • Go Concurrency Part 1
    • Go Concurrency Part 2
  • WebSocket Server
    • WebSocket Handler
    • Build a Chatroom
  • User Authentication
    • Go Module
    • Popular Web Libraries
    • React Tools
    • Build an Authentication Server
  • Numerical Computing
    • Gonum
    • Neural Networks
Powered by GitBook
On this page
  • Setup
  • HTTP Server
  • Project Calculator
  • Source
  1. HTTP Server

Build a Calculator

PreviousHTTP HandlerNextHTTP Unit Test

Last updated 5 years ago

Setup

Create a folder named calculator in your go-academy directory. We don't need to create additional packages for this project. We can keep everything in the package main.

HTTP Server

We are going to use Go's built-in package net/http to create a calculator server. The server should have 4 API GET endpoints, each endpoint serves a different arithmetic operation.

For example,

  • api/add does addition

  • api/sub does subtraction

  • api/mul does multiplication

  • api/div does division

Each endpoint takes in 2 query parameters, left operand and right operand, denoted by lop and rop.

Project Calculator

Source

GitHub
https://www.youtube.com/watch?v=_baFDzyZxPg&feature=youtu.bewww.youtube.com