<commit_before>package models

import (
	"errors"
	"fmt"
	"strings"
	"time"
	"github.com/speps/go-hashids"
	"gopkg.in/olivere/elastic.v3"
	"github.com/eywa/connections"
	. "github.com/eywa/utils"
)

var SupportedDataTypes = []string{"float", "int", "boolean"}
var InternalTags = []string{"ip", "device_id", "channel_name", "timestamp", "request_id"}
var Salt = "Cc4D5xBlbCBqYTuimuNPGsio7YoMo8d8"
var HashLen = 16

type Channel struct {
	Id              int         `sql:"type:integer primary key autoincrement" json:"-"`
	Name            string      `sql:"type:varchar(255);unique_index" json:"name"`
	Description     string      `sql:"type:text" json:"description"`
	Created         int64       `sql:"type:integer" json:"created"`
	Modified        int64       `sql:"type:integer" json:"modified"`
	Tags            StringSlice `sql:"type:text" json:"tags"`
	Fields          StringMap   `sql:"type:text" json:"fields"`
	MessageHandlers StringSlice `sql:"type:text" json:"-"`
	AccessTokens    StringSlice `sql:"type:text" json:"access_tokens"`
	ConnectionLimit int         `sql:"type:integer" json:"connection_limit"`
	MessageRate     int         `sql:"type:integer" json:"message_rate"`
}

func (c *Channel) validate() error {
	if len(c.Name) == 0 {
		return errors.New("name is empty")
	}

	if len(c.Description) == 0 {
		return errors.New("description is empty")
	}

	if c.ConnectionLimit < 0 {
		return errors.New("connection limit is negative")
	}

	if c.MessageRate < 0 {
		return errors.New("message rate is negative")
	}

	if c.Tags == nil {
		c.Tags = StringSlice(make([]string, 0))<commit_msg>connect limit and message rate should be positive<commit_after>package models

import (
	"errors"
	"fmt"
	"strings"
	"time"
	"github.com/speps/go-hashids"
	"gopkg.in/olivere/elastic.v3"
	"github.com/eywa/connections"
	. "github.com/eywa/utils"
)

var SupportedDataTypes = []string{"float", "int", "boolean"}
var InternalTags = []string{"ip", "device_id", "channel_name", "timestamp", "request_id"}
var Salt = "Cc4D5xBlbCBqYTuimuNPGsio7YoMo8d8"
var HashLen = 16

type Channel struct {
	Id              int         `sql:"type:integer primary key autoincrement" json:"-"`
	Name            string      `sql:"type:varchar(255);unique_index" json:"name"`
	Description     string      `sql:"type:text" json:"description"`
	Created         int64       `sql:"type:integer" json:"created"`
	Modified        int64       `sql:"type:integer" json:"modified"`
	Tags            StringSlice `sql:"type:text" json:"tags"`
	Fields          StringMap   `sql:"type:text" json:"fields"`
	MessageHandlers StringSlice `sql:"type:text" json:"-"`
	AccessTokens    StringSlice `sql:"type:text" json:"access_tokens"`
	ConnectionLimit int         `sql:"type:integer" json:"connection_limit"`
	MessageRate     int         `sql:"type:integer" json:"message_rate"`
}

func (c *Channel) validate() error {
	if len(c.Name) == 0 {
		return errors.New("name is empty")
	}

	if len(c.Description) == 0 {
		return errors.New("description is empty")
	}

	if c.ConnectionLimit <= 0 {
		return errors.New("connection limit is negative")
	}

	if c.MessageRate <= 0 {
		return errors.New("message rate is negative")
	}

	if c.Tags == nil {
		c.Tags = StringSlice(make([]string, 0))
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.012345679012345678, 'mean_word_length': 3.78023598820059, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7084259', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1079, 'n_words': 246}