go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yaml omitempty

erkylima opened this issue · comments

I was using this library, but we have a problem and i can try to fix it, Anyone more have the problem that can't omit empty data? It's a great function that will improve this library a lot.

It's a yaml generated with this library, but i wish omit the empty fields to reduce the file size. What do you think about that?

version: "3.7"
services:
    - container_name: PHP
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: NodeJS
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: Go
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: Java
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: Python
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C++
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C#
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C++
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C#
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
    - container_name: C
      build:
        context: ../
        dockerfile: .devops/Dockerfile
      volumes: []
      ports: []
      depends_on: []
      environment: []
      image: ""
networks:
    - das
volumes:
    - das

Hi @erkylima
Could you please provide a sample code for generating a shorter version of the output in this comment?