serv

package
Version: v0.16.95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2021 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

Package serv provides an API to include and use the GraphJin service with your own code. For detailed documentation visit https://graphjin.com

Example usage:

package main

import (
	"database/sql"
	"fmt"
	"time"
	"github.com/dosco/graphjin/core"
	_ "github.com/jackc/pgx/v4/stdlib"
)

func main() {
	conf := serv.Config{ AppName: "Test App" }
	conf.DB.Host := "127.0.0.1"
	conf.DB.Port := 5432
	conf.DB.DBName := "test_db"
	conf.DB.User := "postgres"
	conf.DB.Password := "postgres"

	gjs, err := serv.NewGraphJinService(conf)
	if err != nil {
		log.Fatal(err)
	}

 	if err := gjs.Start(); err != nil {
		log.Fatal(err)
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name     string
	SQL      string
	AuthName string `mapstructure:"auth_name"`
}

Action struct contains config values for a GraphJin service action

type Auth

type Auth = auth.Auth

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

func GetBuildInfo

func GetBuildInfo() BuildInfo

type Config

type Config struct {

	// Core holds config values for the GraphJin compiler
	Core `mapstructure:",squash"`

	// Serv holds config values for the GraphJin Service
	Serv `mapstructure:",squash"`
	// contains filtered or unexported fields
}

Config struct holds the GraphJin service config values

func ReadInConfig

func ReadInConfig(configFile string) (*Config, error)

ReadInConfig function reads in the config file for the environment specified in the GO_ENV environment variable. This is the best way to create a new GraphJin config.

func (*Config) RelPath

func (c *Config) RelPath(p string) string

type Core

type Core = core.Config

type Database

type Database struct {
	Type        string
	Host        string
	Port        uint16
	DBName      string
	User        string
	Password    string
	Schema      string
	PoolSize    int32         `mapstructure:"pool_size"`
	MaxRetries  int           `mapstructure:"max_retries"`
	PingTimeout time.Duration `mapstructure:"ping_timeout"`
	EnableTLS   bool          `mapstructure:"enable_tls"`
	ServerName  string        `mapstructure:"server_name"`
	ServerCert  string        `mapstructure:"server_cert"`
	ClientCert  string        `mapstructure:"client_cert"`
	ClientKey   string        `mapstructure:"client_key"`
}

Database config

type JWTConfig

type JWTConfig = auth.JWTConfig

type RateLimiter

type RateLimiter struct {
	Rate     float64
	Bucket   int
	IPHeader string `mapstructure:"ip_header"`
}

RateLimiter sets the API rate limits

type Serv

type Serv struct {
	// AppName is the name of your application used in log and debug messages
	AppName string `mapstructure:"app_name"`

	// Production when set to true runs the service with production level
	// security and other defaults. For example allow lists are enforced.
	Production bool

	// ConfigPath is the default path to find all configuration
	// files and scripts under
	ConfigPath string `mapstructure:"config_path"`

	// LogLevel can be debug, error, warn, info
	LogLevel string `mapstructure:"log_level"`

	// LogFormat can be json or simple
	LogFormat string `mapstructure:"log_format"`

	// HostPost to run the service on. Example localhost:8080
	HostPort string `mapstructure:"host_port"`

	// Host to run the service on
	Host string

	// Port to run the service on
	Port string

	// HTTPGZip enables HTTP compresssion
	HTTPGZip bool `mapstructure:"http_compress"`

	// Enable the web UI. Disabled in production
	WebUI bool `mapstructure:"web_ui"`

	// EnableTracing enables OpenTrace request tracing
	EnableTracing bool `mapstructure:"enable_tracing"`

	// WatchAndReload enables reloading the service on config changes
	WatchAndReload bool `mapstructure:"reload_on_config_change"`

	// AuthFailBlock when enabled blocks requests with a 401 on auth failure
	AuthFailBlock bool `mapstructure:"auth_fail_block"`

	// SeedFile is the path to the database seeding script
	SeedFile string `mapstructure:"seed_file"`

	// MigrationsPath is the path to the database migration files
	MigrationsPath string `mapstructure:"migrations_path"`

	// AllowedOrigins sets the HTTP CORS Access-Control-Allow-Origin header
	AllowedOrigins []string `mapstructure:"cors_allowed_origins"`

	// AllowedHeaders sets the HTTP CORS Access-Control-Allow-Headers header
	AllowedHeaders []string `mapstructure:"cors_allowed_headers"`

	// DebugCORS enables debug logs for cors
	DebugCORS bool `mapstructure:"cors_debug"`

	// APIPath change the suffix of the api path. Defaults to /v1/graphql
	APIPath string `mapstructure:"api_path"`

	// CacheControl sets the HTTP Cache-Control header
	CacheControl string `mapstructure:"cache_control"`

	// Telemetry struct contains OpenCensus metrics and tracing related config
	Telemetry Telemetry

	// Auth set the default auth used by the service
	Auth Auth

	// Auths sets multiple auths to be used by actions
	Auths []Auth

	// DB struct contains db config
	DB Database `mapstructure:"database"`

	Actions []Action

	// RateLimiter sets the API rate limits
	RateLimiter RateLimiter `mapstructure:"rate_limiter"`
}

Serv struct contains config values used by the GraphJin service

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewGraphJinService

func NewGraphJinService(conf *Config) (*Service, error)

func (*Service) Attach

func (s *Service) Attach(mux *http.ServeMux) error

func (*Service) NewDB

func (s *Service) NewDB(useDB bool) (*sql.DB, error)

func (*Service) Start

func (s *Service) Start() error

type Telemetry

type Telemetry struct {
	// Debug enables debug logging for metrics and tracing data.
	Debug bool

	// Interval to send out metrics and tracing data
	Interval *time.Duration

	Metrics struct {
		// Exporter is the name of the metrics exporter to use. Example: prometheus
		Exporter string

		// Endpoint to send the data to.
		Endpoint string

		// Namespace is set based on your exporter configration
		Namespace string

		// Key is set based on your exporter configuration
		Key string
	}

	Tracing struct {
		// Exporter is the name of the tracing exporter to use. Example: zipkin
		Exporter string

		// Endpoint to send the data to. Example: http://zipkin:9411/api/v2/spans
		Endpoint string

		// Sample sets how many requests to sample for tracing: Example: 0.6
		Sample string

		// IncludeQuery when set the GraphQL query is included in the tracing data
		IncludeQuery bool `mapstructure:"include_query"`

		// IncludeParams when set variables used with the query are included in the
		// tracing data
		IncludeParams bool `mapstructure:"include_params"`

		// ExcludeHealthCheck when set health check tracing is excluded from the
		// tracing data
		ExcludeHealthCheck bool `mapstructure:"exclude_health_check"`
	}
}

Telemetry struct contains OpenCensus metrics and tracing related config

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto