profile

package module
v0.0.0-...-d4b1cd9 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 15 Imported by: 0

README

profile

Build Status | codecov | Go Report Card | GoDoc

A service used on a web site for a person profile (Web Site) github.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

With support for

  • Get sections
  • Get sections with contents
  • Get a section
  • Get a section contents

Endpoints

  • Get sections:

    Method: GET

    Route: http://localhost:9001/api/v1/profile/sections

    Body:

    [
        {
            "id_section": "1",
            "key": "home",
            "name": "Home",
            "description": "Home Section",
        },
        {
            "id_section": "2",
            "key": "projects",
            "name": "Projects",
            "description": "Projects Section",
        },
        {
            "id_section": "3",
            "key": "about",
            "name": "About",
            "description": "About Section",
        }
    ]
    
  • Get sections with contents:

    Method: GET

    Route: http://localhost:9001/api/v1/profile/sections/contents

    Body:

    [
        {
            "id_section": "1",
            "key": "home",
            "name": "Hello",
            "description": "Home Section",
            "contents": [
                {
                    "id_content": "1",
                    "key": "hello",
                    "type": "project",
                    "content": {
                        "url": "https://www.facebook.com/joaosoft",
                        "title": "I'm João Ribeiro",
                        "description": "I like to code."
                    }
                }
            ]
        },
        {
            "id_section": "2",
            "key": "projects",
            "name": "Projects",
            "description": "Projects Section",
            "contents": [
                {
                    "id_content": "2",
                    "key": "dbr",
                    "type": "project",
                    "content": {
                        "url": "https://github.com/joaosoft/dbr",
                        "build": "https://travis-ci.org/joaosoft/dbr.svg?branch=master",
                        "title": "Dbr",
                        "description": "A simple database client with support for master/slave databases."
                    }
                },
                {
                    "id_content": "3",
                    "key": "web",
                    "type": "project",
                    "content": {
                        "url": "https://github.com/joaosoft/web",
                        "build": "https://travis-ci.org/joaosoft/web.svg?branch=master",
                        "title": "Web",
                        "description": "A simple and fast web server and client."
                    }
                },
                {
                    "id_content": "4",
                    "key": "validator",
                    "type": "project",
                    "content": {
                        "url": "https://github.com/joaosoft/validator",
                        "build": "https://travis-ci.org/joaosoft/validator.svg?branch=master",
                        "title": "Validator",
                        "description": "A simple struct validator by tags."
                    }
                }
            ]
        },
        {
            "id_section": "3",
            "key": "about",
            "name": "Goodbye",
            "description": "About Section",
            "contents": [
                {
                    "id_content": "5",
                    "key": "goodbuye",
                    "type": "project",
                    "content": {
                        "url": "https://www.facebook.com/joaosoft",
                        "title": "Thanks for reading",
                        "description": "Find more about me..."
                    }
                }
            ]
        }
    ]
    
  • Get a section:

    Method: PUT

    Route: http://localhost:9001/api/v1/profile/sections/home

    Body:

    {
        "id_section": "1",
        "key": "home",
        "name": "Home",
        "description": "Home Section",
    }
    
  • Get a section contents:

    Method: PUT

    Route: http://localhost:9001/api/v1/profile/sections/projects/contents

    Body:

    {
        "id_section": "2",
        "key": "projects",
        "name": "Projects",
        "description": "Projects Section",
        "contents": [
            {
                "id_content": "2",
                "key": "dbr",
                "type": "project",
                "content": {
                    "url": "https://github.com/joaosoft/dbr",
                    "build": "https://travis-ci.org/joaosoft/dbr.svg?branch=master",
                    "title": "Dbr",
                    "description": "A simple database client with support for master/slave databases."
                }
            },
            {
                "id_content": "3",
                "key": "web",
                "type": "project",
                "content": {
                    "url": "https://github.com/joaosoft/web",
                    "build": "https://travis-ci.org/joaosoft/web.svg?branch=master",
                    "title": "Web",
                    "description": "A simple and fast web server and client."
                }
            },
            {
                "id_content": "4",
                "key": "validator",
                "type": "project",
                "content": {
                    "url": "https://github.com/joaosoft/validator",
                    "build": "https://travis-ci.org/joaosoft/validator.svg?branch=master",
                    "title": "Validator",
                    "description": "A simple struct validator by tags."
                }
            }
        ]
    }
    

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get
Go
go get github.com/joaosoft/profile

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotFound    = errors.New(errors.LevelError, int(web.StatusNotFound), "user not found")
	ErrorInvalidType = errors.New(errors.LevelError, int(web.StatusNotFound), "invalid type")
)

Functions

func EncodeString

func EncodeString(s string) string

func Exists

func Exists(file string) bool

func GetEnv

func GetEnv() string

func ReadFile

func ReadFile(file string, obj interface{}) ([]byte, error)

func ReadFileLines

func ReadFileLines(file string) ([]string, error)

func WriteFile

func WriteFile(file string, obj interface{}) error

Types

type AppConfig

type AppConfig struct {
	Profile *ProfileConfig `json:"profile"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type Content

type Content struct {
	IdContent string           `json:"id_content" db:"id_content"`
	Key       string           `json:"key" db:"key"`
	Type      string           `json:"type" db:"type"`
	Content   *json.RawMessage `json:"content" db:"content"`
}

type ContentList

type ContentList []*Content

func (*ContentList) Scan

func (l *ContentList) Scan(src interface{}) error

func (*ContentList) Value

func (l *ContentList) Value() (driver.Value, error)

type Controller

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

func NewController

func NewController(config *ProfileConfig, interactor *Interactor) *Controller

func (*Controller) GetSectionContentsHandler

func (c *Controller) GetSectionContentsHandler(ctx *web.Context) error

func (*Controller) GetSectionHandler

func (c *Controller) GetSectionHandler(ctx *web.Context) error

func (*Controller) GetSectionsContentsHandler

func (c *Controller) GetSectionsContentsHandler(ctx *web.Context) error

func (*Controller) GetSectionsHandler

func (c *Controller) GetSectionsHandler(ctx *web.Context) error

func (*Controller) RegisterRoutes

func (c *Controller) RegisterRoutes(w manager.IWeb) error

type ErrorResponse

type ErrorResponse struct {
	Code    web.Status `json:"code,omitempty"`
	Message string     `json:"message,omitempty"`
	Cause   string     `json:"cause,omitempty"`
}

type GetSectionContentsRequest

type GetSectionContentsRequest struct {
	SectionKey string `json:"section_key" validate:"notzero"`
}

type GetSectionRequest

type GetSectionRequest struct {
	SectionKey string `json:"section_key" validate:"notzero"`
}

type IStorageDB

type IStorageDB interface {
	GetSections() (SectionList, error)
	GetSectionsContents() (SectionsContentsList, error)
	GetSection(sectionKey string) (*Section, error)
	GetSectionContents(sectionKey string) (*SectionContents, error)
}

type Interactor

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

func NewInteractor

func NewInteractor(logger logger.ILogger, storageDB IStorageDB) *Interactor

func (*Interactor) GetSection

func (i *Interactor) GetSection(request *GetSectionRequest) (*Section, error)

func (*Interactor) GetSectionContents

func (i *Interactor) GetSectionContents(request *GetSectionContentsRequest) (*SectionContents, error)

func (*Interactor) GetSections

func (i *Interactor) GetSections() (SectionList, error)

func (*Interactor) GetSectionsContents

func (i *Interactor) GetSectionsContents() (SectionsContentsList, error)

type Profile

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

func NewProfile

func NewProfile(options ...ProfileOption) (*Profile, error)

NewProfile ...

func (*Profile) Reconfigure

func (profile *Profile) Reconfigure(options ...ProfileOption)

Reconfigure ...

func (*Profile) Start

func (m *Profile) Start() error

Start ...

func (*Profile) Stop

func (m *Profile) Stop() error

Stop ...

type ProfileConfig

type ProfileConfig struct {
	Host      string                     `json:"host"`
	Dbr       *dbr.DbrConfig             `json:"dbr"`
	Migration *migration.MigrationConfig `json:"migration"`
	Log       struct {
		Level string `json:"level"`
	} `json:"log"`
}

ProfileConfig ...

type ProfileOption

type ProfileOption func(profile *Profile)

ProfileOption ...

func WithConfiguration

func WithConfiguration(config *ProfileConfig) ProfileOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) ProfileOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) ProfileOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) ProfileOption

WithManager ...

type Section

type Section struct {
	IdSection   string `json:"id_section" db:"id_section"`
	Key         string `json:"key" db:"key"`
	Name        string `json:"name" db:"name"`
	Description string `json:"description" db:"description"`
}

type SectionContents

type SectionContents struct {
	Section
	Contents ContentList `json:"contents" db:"contents"`
}

type SectionList

type SectionList []*Section

type SectionsContentsList

type SectionsContentsList []*SectionContents

type StoragePostgres

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

func NewStoragePostgres

func NewStoragePostgres(config *ProfileConfig) (*StoragePostgres, error)

func (*StoragePostgres) GetSection

func (storage *StoragePostgres) GetSection(sectionKey string) (*Section, error)

func (*StoragePostgres) GetSectionContents

func (storage *StoragePostgres) GetSectionContents(sectionKey string) (*SectionContents, error)

func (*StoragePostgres) GetSections

func (storage *StoragePostgres) GetSections() (SectionList, error)

func (*StoragePostgres) GetSectionsContents

func (storage *StoragePostgres) GetSectionsContents() (SectionsContentsList, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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