main

mattermost/focalboard

Last updated at: 29/12/2023 09:40

params.go

TLDR

This file defines a type Params and a type ErrStoreParam. The Params type includes several fields and a method CheckValid(), while the ErrStoreParam type includes fields and a method Error().

Classes

Params

This class represents the parameters required for interacting with the mattermost-server. It has the following fields:

  • DBType (string): the type of the database
  • ConnectionString (string): the connection string for the database
  • TablePrefix (string): the table prefix for the database
  • Logger (mlog.LoggerIFace): the logger interface for logging
  • DB (*sql.DB): the database connection pool
  • IsPlugin (bool): indicates if this is used in plugin mode
  • IsSingleUser (bool): indicates if this is used in single user mode
  • NewMutexFn (MutexFactory): the factory function for creating mutexes
  • ServicesAPI (servicesAPI): the interface for interacting with the mattermost-server
  • SkipMigrations (bool): indicates if migrations should be skipped
  • ConfigFn (func() *mmModel.Config): the function for retrieving the mattermost-server configuration

It also has a method:

  • CheckValid(): checks if the parameters are valid, returning an error if they are not.

ErrStoreParam

This class represents an error in the store parameters. It has the following fields:

  • name (string): the name of the parameter
  • issue (string): the issue with the parameter

It also has a method:

  • Error(): returns a string representation of the error.
package sqlstore

import (
	"database/sql"
	"fmt"

	mmModel "github.com/mattermost/mattermost-server/v6/model"

	"github.com/mattermost/mattermost-server/v6/shared/mlog"
)

// servicesAPI is the interface required my the Params to interact with the mattermost-server.
// You can use plugin-api or product-api adapter implementations.
type servicesAPI interface {
	GetChannelByID(string) (*mmModel.Channel, error)
}

type Params struct {
	DBType           string
	ConnectionString string
	TablePrefix      string
	Logger           mlog.LoggerIFace
	DB               *sql.DB
	IsPlugin         bool
	IsSingleUser     bool
	NewMutexFn       MutexFactory
	ServicesAPI      servicesAPI
	SkipMigrations   bool
	ConfigFn         func() *mmModel.Config
}

func (p Params) CheckValid() error {
	if p.IsPlugin && p.NewMutexFn == nil {
		return ErrStoreParam{name: "NewMutexFn", issue: "cannot be nil in plugin mode"}
	}
	return nil
}

type ErrStoreParam struct {
	name  string
	issue string
}

func (e ErrStoreParam) Error() string {
	return fmt.Sprintf("invalid store params: %s %s", e.name, e.issue)
}