Convert Figma logo to code with AI

nytimes logogizmo

A Microservice Toolkit from The New York Times

3,759
225
3,759
33

Top Related Projects

38,510

Developer-first error tracking and performance monitoring

OpenTracing API for Go. 🛑 This library is DEPRECATED! https://github.com/opentracing/specification/issues/163

20,309

CNCF Jaeger, a Distributed Tracing Platform

Quick Overview

The nytimes/gizmo repository is a Go web framework and toolkit developed by The New York Times. It provides a set of packages and utilities to build robust, scalable, and maintainable web applications and microservices.

Pros

  • Modular and Extensible: Gizmo is designed with a modular architecture, allowing developers to pick and choose the components they need for their project, making it highly customizable.
  • Opinionated but Flexible: Gizmo provides a set of best practices and conventions, but still allows developers to deviate from them if necessary, providing a balance between structure and flexibility.
  • Comprehensive Toolset: Gizmo includes a wide range of packages and utilities, covering areas such as service registration, metrics, tracing, and more, reducing the need for additional third-party libraries.
  • Production-Ready: Gizmo has been battle-tested in production environments at The New York Times, ensuring its reliability and robustness.

Cons

  • Steep Learning Curve: Gizmo's comprehensive feature set and opinionated design may require a significant investment of time and effort to fully understand and utilize.
  • Limited Community: Compared to more popular Go web frameworks, Gizmo has a smaller community, which may result in fewer resources, tutorials, and third-party integrations.
  • Potential Vendor Lock-in: As Gizmo was developed and is primarily used by The New York Times, there is a risk of potential vendor lock-in for projects that heavily rely on its specific features and conventions.
  • Lack of Official Documentation: While Gizmo's codebase is well-documented, the project's official documentation could be more comprehensive, making it harder for new users to get started.

Code Examples

Here are a few examples of how to use Gizmo in your Go projects:

  1. Creating a Simple HTTP Server:
package main

import (
    "net/http"

    "github.com/nytimes/gizmo/server"
)

func main() {
    svc := &myService{}
    server.Run(svc)
}

type myService struct{}

func (s *myService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Hello, Gizmo!"))
}
  1. Registering a Service with Consul:
package main

import (
    "github.com/nytimes/gizmo/config"
    "github.com/nytimes/gizmo/server"
)

func main() {
    cfg := &myConfig{}
    config.Load(cfg)

    svc := &myService{
        config: cfg,
    }

    server.RegisterService(svc)
    server.Run(svc)
}

type myConfig struct {
    ConsulAddress string `envconfig:"CONSUL_ADDRESS"`
}

type myService struct {
    config *myConfig
}
  1. Implementing a Metrics-Enabled Endpoint:
package main

import (
    "net/http"

    "github.com/nytimes/gizmo/metrics"
    "github.com/nytimes/gizmo/server"
)

func main() {
    svc := &myService{}
    server.Run(svc)
}

type myService struct{}

func (s *myService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    defer metrics.Measure("my-endpoint", []string{}, func() {
        w.Write([]byte("Hello, Gizmo!"))
    })
}

Getting Started

To get started with Gizmo, follow these steps:

  1. Install the Gizmo package:
go get github.com/nytimes/gizmo
  1. Create a new Go module for your project:
go mod init my-project
  1. Create a new Gizmo service:
package main

import (
    "github.com/nytimes/gizmo/server"
)

type myService struct{}

func (s *myService) Serve

Competitor Comparisons

38,510

Developer-first error tracking and performance monitoring

Pros of Sentry

  • Sentry is a widely-used and well-established error tracking and monitoring platform, with a large and active community.
  • Sentry provides a comprehensive set of features for capturing, analyzing, and resolving errors and exceptions in web and mobile applications.
  • Sentry has a robust and flexible SDK ecosystem, allowing integration with a wide range of programming languages and frameworks.

Cons of Sentry

  • Sentry can be more complex to set up and configure compared to simpler error logging solutions.
  • Sentry's pricing model may be more expensive for small or personal projects, as it is primarily designed for enterprise-level applications.
  • Sentry's focus on enterprise-level features may make it overkill for some smaller-scale projects.

Code Comparison

Here's a brief code comparison between Sentry and Gizmo:

Sentry (Python):

import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    integrations=[
        FlaskIntegration(),
    ],
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production.
    traces_sample_rate=1.0
)

Gizmo (Go):

package main

import (
    "net/http"

    "github.com/nytimes/gizmo/server"
)

func main() {
    svc := &myService{}
    server.Run(svc)
}

type myService struct{}

func (s *myService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Hello, World!"))
}

OpenTracing API for Go. 🛑 This library is DEPRECATED! https://github.com/opentracing/specification/issues/163

Pros of opentracing/opentracing-go

  • Vendor-Neutral API: OpenTracing provides a vendor-neutral API for distributed tracing, allowing applications to be instrumented independently of the underlying tracing implementation.
  • Language Support: The OpenTracing project has implementations in various programming languages, including Go, Java, Python, and more, enabling consistent tracing across different components of a distributed system.
  • Flexibility: OpenTracing allows for the use of different tracing backends, such as Jaeger, Zipkin, or custom solutions, providing flexibility in the choice of tracing infrastructure.

Cons of opentracing/opentracing-go

  • Complexity: Integrating OpenTracing into an existing application may require additional setup and configuration, which can add complexity to the development process.
  • Overhead: The use of OpenTracing can introduce some performance overhead due to the additional instrumentation and data collection required for distributed tracing.

Code Comparison

OpenTracing/opentracing-go:

func main() {
    tracer, closer, err := tracing.Init("my-service")
    if err != nil {
        panic(err)
    }
    defer closer.Close()

    span := tracer.StartSpan("my-operation")
    defer span.Finish()

    // Perform some operation
    // ...
}

nytimes/gizmo:

func main() {
    cfg := config.New()
    app := kit.NewServer(cfg)

    app.RegisterHealthHandler(func() bool {
        // Implement health check logic
        return true
    })

    app.Run()
}
20,309

CNCF Jaeger, a Distributed Tracing Platform

Pros of Jaeger

  • Jaeger is a popular and widely-used open-source distributed tracing system, providing a comprehensive solution for monitoring and troubleshooting microservices-based applications.
  • Jaeger offers a user-friendly web UI for visualizing and analyzing traces, making it easier to understand the behavior of complex distributed systems.
  • Jaeger supports a wide range of programming languages and platforms, making it a versatile choice for various development environments.

Cons of Jaeger

  • Jaeger may have a steeper learning curve compared to Gizmo, as it is a more feature-rich and complex system.
  • Jaeger's deployment and configuration can be more involved, especially in large-scale environments, compared to the simpler setup of Gizmo.

Code Comparison

Gizmo (nytimes/gizmo):

func main() {
    app := gizmo.NewSimpleServer(
        &config.Config{
            ServiceName: "my-service",
            HTTPPort:    8080,
        },
    )

    app.RegisterHealthCheck(func() error {
        // implement your health check logic here
        return nil
    })

    app.RegisterEndpoint("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello, World!")
    }))

    app.Run()
}

Jaeger (jaegertracing/jaeger):

func main() {
    cfg, err := config.FromEnv()
    if err != nil {
        log.Fatalf("Could not read configuration from environment: %v", err)
    }

    tracer, closer, err := cfg.NewTracer()
    if err != nil {
        log.Fatalf("Could not initialize tracer: %v", err)
    }
    defer closer.Close()

    opentracing.SetGlobalTracer(tracer)

    // Your application code goes here
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Gizmo Microservice Toolkit GoDoc Build Status Coverage Status

As of late April, 2021 Gizmo has been placed in maintenance mode.

This toolkit provides packages to put together server and pubsub daemons with the following features:

  • Standardized configuration and logging
  • Health check endpoints with configurable strategies
  • Configuration for managing pprof endpoints and log levels
  • Basic interfaces to define expectations and vocabulary
  • Structured logging containing basic request information
  • Useful metrics for endpoints
  • Graceful shutdowns

Install

Notice the capitalization!

go get github.com/NYTimes/gizmo/...

Import Path Change Notice

The New York Times recently changed the github organization from NYTimes to nytimes. This should not affect the installation as long as you use the proper casing NYTimes and not nytimes per installation instructions above.

However, the intention is to migrate the import paths to be consistent with how it's shown on GitHub. This will be a breaking change and we will introduce a major tag when we update the code. Therefore, the import path will go from github.com/NYTimes/gizmo/server to github.com/nytimes/gizmo/v2/server. This ensures that people will not have type-mismatches between import path changes.

Packages

server

The server package is the bulk of the toolkit and relies on server.Config to manage Server implementations.

It offers 1 server implementation:

SimpleServer, which is capable of handling basic HTTP and JSON requests via 5 of the available Service implementations: SimpleService, JSONService, ContextService, MixedService and a MixedContextService.

server/kit

The server/kit package embodies Gizmo's goals to combine with go-kit.

  • In this package you'll find:
    • A more opinionated server with fewer choices.
    • go-kit used for serving HTTP/JSON & gRPC used for serving HTTP2/RPC
    • Monitoring, traces and metrics are automatically registered if running within App Engine, Cloud Run, Kubernetes Engine, Compute Engine or AWS EC2 Instances.
      • to change the name and version for Error reporting and Traces use SERVICE_NAME and SERVICE_VERSION environment variables.
    • Logs go to stdout locally or directly to Stackdriver when in GCP.
    • Using Go's 1.8 graceful HTTP shutdown.
    • Services using this package are expected to deploy to GCP.

observe

The observe package provides observability helpers for metrics and tracing through OpenCensus

  • server/kit (and soon SimpleServer) utilizes this package to create a StackDriver exporter with sane defaults
  • GoogleProjectID, IsGAE, and IsCloudRun can help you make decisions about the underlying platform

auth

The auth package provides primitives for verifying inbound authentication tokens:

  • The PublicKeySource interface is meant to provide *rsa.PublicKeys from JSON Web Key Sets.
  • The Verifier struct composes key source implementations with custom decoders and verifier functions to streamline server side token verification.

auth/gcp

The auth/gcp package provides 2 Google Cloud Platform based auth.PublicKeySource and oauth2.TokenSource implementations:

  • The "Identity" key source and token source rely on GCP's identity JWT mechanism for asserting instance identities. This is the preferred method for asserting instance identity on GCP.
  • The "IAM" key source and token source rely on GCP's IAM services for signing and verifying JWTs. This method can be used outside of GCP, if needed and can provide a bridge for users transitioning from the 1st generation App Engine (where Identity tokens are not available) runtime to the 2nd.

The auth/gcp package also includes an Authenticator, which encapsulates a Google Identity verifier and oauth2 credentials to manage a basic web auth flow.

config

The config package contains a handful of useful functions to load to configuration structs from JSON files or environment variables.

There are also many structs for common configuration options and credentials of different Cloud Services and Databases.

pubsub

The pubsub package contains two (publisher and subscriber) generic interfaces for publishing data to queues as well as subscribing and consuming data from those queues.

There are 4 implementations of pubsub interfaces:

  • For pubsub via Amazon's SNS/SQS, you can use the pubsub/aws package

  • For pubsub via Google's Pubsub, you can use the pubsub/gcp package

  • For pubsub via Kafka topics, you can use the pubsub/kafka package

  • For publishing via HTTP, you can use the pubsub/http package

pubsub/pubsubtest

The pubsub/pubsubtest package contains test implementations of the pubsub.Publisher, pubsub.MultiPublisher, and pubsub.Subscriber interfaces that will allow developers to easily mock out and test their pubsub implementations.

Examples

  • Several reference implementations utilizing server and pubsub are available in the examples subdirectory.
  • There are also examples within the GoDoc: here

If you experience any issues please create an issue and/or reach out on the #gizmo channel in the Gophers Slack Workspace with what you've found.

The Gizmo logo was based on the Go mascot designed by Renée French and copyrighted under the Creative Commons Attribution 3.0 license.