serv

package
v0.17.24 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 66 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

func GetConfigName added in v0.17.7

func GetConfigName() string

func InitAdmin added in v0.17.0

func InitAdmin(db *sql.DB, dbtype string) error

func NewDB added in v0.17.0

func NewDB(conf *Config, openDB bool, log *zap.SugaredLogger, fs afero.Fs) (*sql.DB, error)

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 Admin added in v0.17.0

type Admin struct {
	// HotDeploy enables the ability to hot-deploy a new configuration
	// to GraphJin.
	HotDeploy bool `mapstructure:"hot_deploy"`

	// AdminSecret is the secret key used to control access
	// to the admin api
	AdminSecretKey string `mapstructure:"admin_secret_key"`
}

Admin struct contains config values used for adminstration of the GraphJin service

type Auth added in v0.16.38

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"`

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

Config struct holds the GraphJin service config values

func NewConfig added in v0.17.13

func NewConfig(config, format string) (*Config, error)

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 ReadInConfigFS added in v0.17.0

func ReadInConfigFS(configFile string, fs afero.Fs) (*Config, error)

ReadInConfigFS is the same as ReadInConfig but it also takes a filesytem as an argument

func (*Config) GetSecret added in v0.17.24

func (c *Config) GetSecret(k string) (string, bool)

func (*Config) GetSecretOrEnv added in v0.17.24

func (c *Config) GetSecretOrEnv(k string) string

func (*Config) RelPath

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

func (*Config) SetHash added in v0.17.0

func (c *Config) SetHash(hash string)

func (*Config) SetName added in v0.17.0

func (c *Config) SetName(name string)

type Core

type Core = core.Config

type Database added in v0.16.56

type Database struct {
	Type            string
	Host            string
	Port            uint16
	DBName          string
	User            string
	Password        string
	Schema          string
	PoolSize        int           `mapstructure:"pool_size"`
	MaxConnections  int           `mapstructure:"max_connections"`
	MaxConnIdleTime time.Duration `mapstructure:"max_connection_idle_time"`
	MaxConnLifeTime time.Duration `mapstructure:"max_connection_life_time"`
	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 added in v0.16.56

type JWTConfig = auth.JWTConfig

type Mux added in v0.17.21

type Mux interface {
	Handle(string, http.Handler)
	ServeHTTP(http.ResponseWriter, *http.Request)
}

type Option added in v0.17.0

type Option func(*service) error

func OptionDeployActive added in v0.17.1

func OptionDeployActive() Option

func OptionSetFS added in v0.17.0

func OptionSetFS(fs afero.Fs) Option

func OptionSetNamespace added in v0.17.22

func OptionSetNamespace(namespace string) Option

func OptionSetZapLogger added in v0.17.24

func OptionSetZapLogger(zlog *zap.Logger) Option

type Payload added in v0.17.13

type Payload struct {
	Data   json.RawMessage `json:"data,omitempty"`
	Errors []core.Error    `json:"errors,omitempty"`
}

type RateLimiter added in v0.16.56

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"`

	// SecretsFile is the file for the secret key store
	SecretsFile string `mapstructure:"secrets_file"`

	// 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 compression
	HTTPGZip bool `mapstructure:"http_compress"`

	// ServerTiming enables the Server-Timing header
	ServerTiming bool `mapstructure:"server_timing"`

	// 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"`

	// 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"`

	// 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 {
	atomic.Value
	// contains filtered or unexported fields
}

func NewGraphJinService added in v0.16.38

func NewGraphJinService(conf *Config, options ...Option) (*Service, error)

func (*Service) Attach

func (s *Service) Attach(mux Mux) error

func (*Service) AttachWithNamespace added in v0.17.22

func (s *Service) AttachWithNamespace(mux Mux, namespace string) error

func (*Service) Deploy added in v0.17.0

func (s *Service) Deploy(conf *Config, options ...Option) error

func (*Service) GetDB added in v0.17.19

func (s *Service) GetDB() *sql.DB

func (*Service) GraphQL added in v0.17.19

func (s *Service) GraphQL(c context.Context,
	query string,
	vars json.RawMessage,
	rc *core.ReqConfig) (*core.Result, error)

func (*Service) Start

func (s *Service) Start() error

func (*Service) Subscribe added in v0.17.19

func (s *Service) Subscribe(
	c context.Context,
	query string,
	vars json.RawMessage,
	rc *core.ReqConfig) (*core.Member, error)

type Telemetry added in v0.16.56

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
module
Package auth provides an API to use GraphJin serv auth handles with your own application.
Package auth provides an API to use GraphJin serv auth handles with your own application.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL