mosso

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

mosso banner
Go Version License Build Status PRs Welcome

MOSSO is a lightweight, out-of-the-box development kit designed for rapid debugging and logging in Go. It helps you visualize complex data structures as formatted JSON directly in your console or save them to a file.

🚀 Installation

go get -u github.com/channellabs/mosso

🌈 Features

  • Convert and print any interface{} to formatted JSON.
  • Automatically trace and display the caller's file name and line number.
  • Add custom informational tags to distinguish different debug outputs.
  • Toggle visual borders (Start/End markers) for better readability.
  • Write the debug output directly to a specific file.
  • Customize the number of blank lines appended at the bottom of the output.

🚢 Quick Start

package main

import (
  "github.com/channellabs/mosso"
)

type Sex uint8

const (
  SexOfUnknown Sex = iota
  SexOfMale
  SexOfFemale
)

type User struct {
  Name string `json:"name"`
  Age  uint8  `json:"age"`
  Sex  Sex    `json:"sex"`
}

func main() {
  var users = []User{
    {
      Name: "tom",
      Age:  18,
      Sex:  SexOfMale,
    },
    {
      Name: "tom",
      Age:  18,
      Sex:  SexOfFemale,
    },
  }

  // Console Output Example:
  // main.go:33
  // --- CurrentType([]main.User) | Start ------------------
  // [
  //   {
  //     "name": "tom",
  //     "age": 18,
  //     "sex": 1
  //   },
  //   {
  //     "name": "tom",
  //     "age": 18,
  //     "sex": 2
  //   }
  // ]
  // --- CurrentType([]main.User) | Finish ------------------
  //
  mosso.DebugShowContentWithJSON(users)
}

🔧 Advanced Usage & Options

mosso uses the functional options pattern, allowing you to highly customize the output to fit your debugging needs.

Customizing Output

data := map[string]string{"username": "fishfinal", "email": "contact.fishfinal@gmail.com"}

// Example: Add an info tag, hide type borders, and write to a file
mosso.DebugShowContentWithJSON(data,
  mosso.WithInfo("UserInfo"),                   // Add a custom tag/description
  mosso.WithSpecificOfVisual(true),             // Show the "Start" and "Finish" borders
  mosso.WithSpecificOfWriteFile(true),          // Enable writing to file
  mosso.WithSpecificOfFilename("hello.json"),   // Specify the output filename (default is mosso.txt)
)

Getting Output as a String

If you don't want to print directly to the console but need the string representation:

jsonStr := mosso.DebugContentWithJSON(data, 
  mosso.WithSpecificOfVisual(false), // Disable borders for clean JSON string
)

⚙ API Overview

Function Description
DebugShowContentWithJSON(data interface{}, ops ...Option) Prints the formatted JSON directly to the standard output.
DebugContentWithJSON(data interface{}, ops ...Option) string Returns the formatted debug string instead of printing it.

Available Options

Option Description
WithSpecificOfFormat(bool) Enable/disable JSON indentation (default: true).
WithInfo(string) Add a custom description/info tag next to the type.
WithSpecificOfVisual(bool) Enable/disable "Start/Finish" visual borders (default: true).
WithSpecificOfShowType(bool) Show/hide the data type in the output (default: true).
WithSpecificOfLineNumber(bool) Show/hide the caller's file name and line number (default: true).
WithSpecificOfBottomSpaceLine(int) Set the number of blank lines at the bottom (default: 1).
WithSpecificOfWriteFile(bool) Enable/disable writing the output to a file (default: false).
WithSpecificOfFilename(string) Set the target filename when writing to a file (default: "mosso.txt").

📝 License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Documentation

Index

Constants

View Source
const (
	DefaultWriteFileName = "mosso.txt"
)

Variables

This section is empty.

Functions

func DebugContentWithJSON

func DebugContentWithJSON(data interface{}, ops ...Option) string

DebugContentWithJSON Get debugging data information, which can be customized by option type method.

func DebugConvertInterfaceToJSONString

func DebugConvertInterfaceToJSONString(in interface{}, format bool) string

DebugConvertInterfaceToJSONString convert object to string.

func DebugShowContentWithJSON

func DebugShowContentWithJSON(data interface{}, ops ...Option)

DebugShowContentWithJSON Output debugging data information, which can be customized by option type method.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithInfo

func WithInfo(info string) Option

func WithSpecificOfBottomSpaceLine

func WithSpecificOfBottomSpaceLine(number int) Option

func WithSpecificOfFilename

func WithSpecificOfFilename(filename string) Option

func WithSpecificOfFormat

func WithSpecificOfFormat(format bool) Option

func WithSpecificOfLineNumber

func WithSpecificOfLineNumber(lineNum bool) Option

func WithSpecificOfShowType

func WithSpecificOfShowType(typ bool) Option

func WithSpecificOfVisual

func WithSpecificOfVisual(visual bool) Option

func WithSpecificOfWriteFile

func WithSpecificOfWriteFile(writeFile bool) Option

Jump to

Keyboard shortcuts

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