Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/leetcode-golang-classroom/golang-stock-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/leetcode-golang-classroom/golang-stock-api

  • v0.0.0-20240703160656-3fdb1bca7c37
  • Source
  • Go
  • Socket score

Version published
Created
Source

golang-stock-api

This repository is implementation of stock tracker by golang

setup stock db

CREATE DATABASE stocksdb;
CREATE TABLE IF NOT EXISTS stocks (
  stockid SERIAL PRIMARY KEY,
  name TEXT,
  price INTEGER,
  company TEXT
);

define App structure

type App struct {
	router *mux.Router
	config *config.Config
	db     *sql.DB
}

setup router with stock service

func NewRouter() *mux.Router {
	router := mux.NewRouter()
	// set default health check
	router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		err := json.NewEncoder(w).Encode(map[string]string{"message": "status ok"})
		if err != nil {
			log.Fatal(err)
		}
	})
	return router
}

func (app *App) loadRoutes() {
	stockStore := stock.NewStore(app.db)
	storeHandler := stock.NewHandler(stockStore)
	storeHandler.RegisterRoute(app.router)
}

define stock structure

type Handler struct {
	stockStore types.StockStore
}

func NewHandler(stockStore types.StockStore) *Handler {
	return &Handler{stockStore: stockStore}
}

dependency graph

dependency graph

injection direction diagram

injection-direction-diagram

purpose

透過把相同職責的元件放到同一個 service 資料夾 folder 下

比如這邊放在 service/stock 下的 go 檔案都是與操作 stock 相關

然後再根據不同的處理範圍分別取名不同,比如是處理 middleware 則放 middleware.go

處理資料狀態處理則放 store.go

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc