[go-nuts] text template and white space suppression

2020-06-28 Thread Bill Nixon
I am trying to do some creative formatting using text template and wanted 
to see if there might be a better approach than what I implemented.

I have an array of structs, where each element has a Project and Task. The 
array is sorted by Project.
type DisplayTask struct {
 Project string
 Task string
}

I want to output all the tasks within a project without repeating the 
project name each time and I want the tasks to be indented, for example:

Project1 
  Task1
  Task2
Project2 
  Task3
Project3 
  Task4
  Task5

After much experimentation, I am using the following template and trying to 
determine if there is a way to avoid the printf and just have the indent as 
part of the template, but I can't figure out a way to do this and suppress 
white space (newline) from the if statement for the same project.
{{- $lastProject := "" -}}
{{ range . }}
{{- if (ne $lastProject .Project) -}}
{{ .Project }} {{ $lastProject = .Project }}
{{ end -}}
  {{ printf "  %s" .Task }}
{{ end -}}

Go Playground of the working code is at 
https://play.golang.org/p/3qqVW8lN-Ha

The challenge I had was suppressing white space after the end, but still 
allowing an indent via white space, so resorted to the printf.

Is there a better way?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8da74f77-a462-4bdf-9491-38e403d8c250o%40googlegroups.com.


[go-nuts] Microsoft Graph for Go

2019-12-08 Thread Bill Nixon
I've been playing with Go and Microsoft Graph and decided to combine the 
two and have been writing a "wrapper" API to the RESTful Microsoft Graph 
APIs.The source is available at https://github.com/bnixon67/msgraph4go

Microsoft Graph exposes REST APIs and client libraries to access data on 
various Microsoft cloud services, including OneDrive, OneNote, 
Outlook/Exchange, SharePoint, Azure Active Directory, etc...

There are SDKs for some popular languages, but I didn't find any for Go.

This has been a great learning experience and I've been impressed with how 
easily Go supports this type of work, with standard libraries for OAuth2, 
HTTP requests, JSON conversion to Go types, etc...

I welcome any feedback or input. I plan to continue to expand the package 
to support more of the Microsoft Graph APIs. So far, I've only done 
read-only operations, but I am considering writing a OneDrive Sync client.

Thanks,
Bill

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/52718dc2-e0f4-4b73-8473-7444b012daec%40googlegroups.com.


[go-nuts] Re: golang tool for splitting long lines

2019-11-24 Thread Bill Nixon
I agree json.MarshalIndent is great. However, be aware that 
json.MarshalIndent will not output private (lowercase) fields of the struct.

On Monday, November 18, 2019 at 3:29:28 AM UTC-6, anderso...@blacklane.com 
wrote:
>
> Hi Sankar,
>
> Not really, a easy trick is to use json.MarshalIndent. It helped me a lot 
> :)
>
> playgound: https://play.golang.org/p/nfr2ANR6pPH
>
> type A struct {
> A int
> B string
> C map[int]string
> }
>
> func main() {
> aa := A{
> A: 1,
> B: "2",
> C: map[int]string{3: "3"},
> }
>
> bs, _ := json.MarshalIndent(aa, "", "")
> fmt.Printf("%#v\n", aa)
> fmt.Println(string(bs))
>
> }
>
>
>
> On Friday, 15 November 2019 06:17:29 UTC+1, Sankar wrote:
>>
>> Hi
>>
>> In Javascript world I have this handy tool Prettier which will 
>> automatically, reproducibly break long lines of code into multiple lines 
>> (and also merge parameters into a single line if some elements are 
>> removed). 
>>
>> Are there similar tools available for Golang ? Either as a standalone 
>> program or as VSCode/Goland plugins.
>>
>> From https://github.com/golang/go/issues/11915 I believe that go team 
>> may not address it as natively as gofmt/goimports. But are there any other 
>> hacks/tools that people already use to break long lines ? 
>>
>> Thanks.
>>
>> Sankar
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b2a80d30-5088-4436-9380-00b45f25cce2%40googlegroups.com.