misura

command module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 10 Imported by: 0

README

misura

misura wraps an interface or a struct and adds prometheus metrics such as success count, error count, total count and duration

THIS IS A WIP

TODO

  • Handle slice ... operator
  • Only work on targets passed not all interfaces in file
  • Pass method name and other method related information Total, Success and Error
  • Get list of targets not just one
    • Check generated file exists, if yes append to it.
    • Create a seperate file for each target.
  • Let users decided what metrics they want
  • Handle time package conflict
  • Add struct wrapping support?
    • Only methods in the same file will be included
    • Add an options to create an interface for the struct aswell
  • Enable users to extend wrapping functionallity to add custom logic to their interfaces
  • Custom metrics? This is solved by accepting metrics interface.
  • Per type method inclusion and exlusion
  • Support both go:generate misura [args] and //misura: [args]
  • Support third party types

Usage

Assume we have the following interface in a .go file.

type IPUtil interface {
	PublicIP() (net.IP, error)
	LocalIPs() ([]net.IP, error)
}

Now to generate a wrapper for this interface we have 2 options:

  1. Put a magic comment for the entire file and passing each interface name with the -t flag.

TODO: add multiple targets using multiple -t args

//go:generate misura -m all -t IPUtil
type IPUtil interface {
	PublicIP() (net.IP, error)
	LocalIPs() ([]net.IP, error)
}
  1. Add a magic comment on top of the file then use //misura:<taget-name> [args] syntax. This method makes the file readable.
package main

//go:generate misura
import (
...
)

//misura:IPUtil -m all
type IPUtil interface {
	PublicIP() (net.IP, error)
	LocalIPs() ([]net.IP, error)
}

Testing

go test ./...
  • Test generated wrappers for compliation
  • Test generated code is as expected using ast, or maybe run them with a utilty program and run it that way.

TODO

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples
readme_usage command
Code generated by github.com/itzloop/misura.
Code generated by github.com/itzloop/misura.

Jump to

Keyboard shortcuts

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